≡ Menu

shell scripting

Bash Shell Read a Line Field By Field

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

device1,deviceType,major,minor,permissions
device2,deviceType,major,minor,permissions
...
....
.
deviceN,deviceTypeN,major,minor,permissions

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
[click to continue…]

Bash: Continue In a For / While Loop

How do I continue in a for or while loop in Bash under UNIX or Linux operating systems?
[click to continue…]

Ksh Read a File Line By Line ( UNIX Scripting )

How do I read a file line by line using KSH shell scripting under UNIX like operating systems?
[click to continue…]

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?
[click to continue…]

Shell Scripting: Check File Size ( Find File Size )

How do I find out file size under UNIX / Linux operating system and store the same to a variable called s?
[click to continue…]

My programs and scripts needs a real path and not a a symbolic link. How to I determine a real path of any directory under Linux / UNIX like operating systems? How do I remove references to /./, /../ and extra '/' character in path?
[click to continue…]

BASH: Prepend A Text / Lines To a File

Q. I can append text to a file using >> operator but how do I prepend a text to a file? I want the opposit of >> operation?
[click to continue…]