How can one assign the output of the shell command to a variable in bash script under unix and linux like operating systems. Bash provides a feature called command substitution. It allows you to run a shell command and store the output of the shell command to a variable in the bash script. The syntax of Full Article…
Unix Shell Script Syntax for if and grep and -gt
There are two errors in your script: Nested backticks are not allowed. $2/$file_z instead of $(<$2/$file_z) Fixed: for j in `<$2/$file_z` do if grep -q “$1” “$j” > /dev/null # if grep “$1” “$j” > /dev/null # if your grep does not support -q then echo $j cp $j $3 fi done More optimal: for j in `<$2/$file_z` do Full Article…
How to format date for display or to use in a shell script
Q. How do I format date to display on screen on for my scripts as per my requirements? A. You need to use standard date command to format date or time for output or to use in a shell script. Syntax to specify format date +FORMAT Task: Display date in mm-dd-yy format Type the command Full Article…
checkprocess.sh – Check process & restart
I have a process that has been crashing every few days, but needs to be running 24/7 to be effective. Until I find the time to seek out the cause, I need the process to be restarted. This short SH script uses PS to check that the process is running, and if not, runs the Full Article…
.sh file syntax checking script
This isn’t a question–its a solution! Below is a script that I wrote for my own script file development which does what the title says. Its the closest that you can get to compiling what are otherwise purely interpreted script files. I offer it here simply for the benefit of anyone else writing script files. Full Article…
Removing Duplicate Lines With Sort, Uniq and Shell Pipes
Use the following syntax: sort {file-name} | uniq -u sort file.log | uniq -u Here is a sample test file called garbage.txt: this is a test food that are killing you wings of fire we hope that the labor spent in creating this software this is a test unix ips as well as enjoy our Full Article…