User Tools

Site Tools


tutorials:bash_scripting:part3

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorials:bash_scripting:part3 [2012/05/29 10:45] rmilestutorials:bash_scripting:part3 [2017/10/12 21:58] (current) – external edit 127.0.0.1
Line 1: Line 1:
 //**3. Creating a configuration file on the fly and stream editing**// //**3. Creating a configuration file on the fly and stream editing**//
  
 +----
 Someone on the list asked If I'd do something with stream editors. In this tutorial I'll use pipes, grep, sed and awk to help set a variable in a configuration file when I log into a session. Grep in this case will be used to print lines matching a given pattern to stdout. Sed will be used to print only one line piped from grep to stdout. Awk will be used to print just one field from the line piped in from sed. Someone on the list asked If I'd do something with stream editors. In this tutorial I'll use pipes, grep, sed and awk to help set a variable in a configuration file when I log into a session. Grep in this case will be used to print lines matching a given pattern to stdout. Sed will be used to print only one line piped from grep to stdout. Awk will be used to print just one field from the line piped in from sed.
  
Line 32: Line 33:
 } }
 </code> </code>
-In order to have the correct souncard setting I will put together a script that runs when I start up a session. It will check the number of my souncard in /proc/asound/cards then re-write my ~/.asoundrc using the correct card number for my C-Media card.+In order to have the correct sound card setting I will put together a script that runs when I start up a session. It will check the number of my sound card in /proc/asound/cards then re-write my ~/.asoundrc using the correct card number for my C-Media card.
  
 The basic script will will create an ~/.asoundrc on the fly. The output of each echo command is redirected to the file ~/.asoundrc when the script runs.  The basic script will will create an ~/.asoundrc on the fly. The output of each echo command is redirected to the file ~/.asoundrc when the script runs. 
Line 59: Line 60:
 This is where stream editing comes in. I can use a variable for the card number and create the variable each time the script is run using the following: This is where stream editing comes in. I can use a variable for the card number and create the variable each time the script is run using the following:
 <code> <code>
-cat /proc/asound/cards | grep CMI | sed q | awk -F " " '{ print $}'+cat /proc/asound/cards | grep CMI | sed q | awk -F " " '{ print $}'
 </code> </code>
 The stdout from each command is piped to the next command until just the card number remains. The stdout from each command is piped to the next command until just the card number remains.
Line 117: Line 118:
 </code> </code>
  
 +----
 +
 +**Cheers!**
  
  
Line 129: Line 133:
  
  
- \npcm.copy {defaults.ctl.card 1\npcm.copy {defaults.ctl.card 1 ~/.asoundrc 
-echo  
tutorials/bash_scripting/part3.1338252322.txt.gz · Last modified: 2017/10/12 21:58 (external edit)