Bash Shell Read a Line Field By Field

Posted on in Categories last updated March 15, 2010

How do I read a file field-by-field under UNIX / Linux / BSD Bash shell? My sample input data file is as follows:



For each line I need to construct and execute a shell command as follows:

/path/to/deviceMaker --context=$1 -m $permissions $device2 $deviceType $major $minor

Shell Scripting: If Variable Is Not Defined, Set Default Variable

Posted on in Categories , , last updated July 27, 2009

If var is defined AND NOT EMPTY, use var, otherwise set a default variable under Bash. For e.g. my script needs a parameter for output variable. It can be text or html. I set it as follows in my script

output=$1 # either text or html

However, sometime user forget to pass the parameter to my shell script and my enter logic fails. So how do I set default value to text, if no parameter passed?