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…
Viewing 1 to 3 of 3 items
unix shell script find out which directory the script file resides?
For bash, sh, ksh: #!/bin/bash # Absolute path to this script, e.g. /home/user/bin/foo.sh SCRIPT=$(readlink -f $0) # Absolute path this script is in, thus /home/user/bin SCRIPTPATH=$(dirname $SCRIPT) echo $SCRIPTPATH For tcsh, csh: #!/bin/tcsh # Absolute path to this script, e.g. /home/user/bin/foo.csh set SCRIPT=`readlink -f $0` # Absolute path this script is in, thus /home/user/bin set Full Article…
Unix shell script to calculate date in the future and in the past
For Linux use the following commands: $ date -d ‘now + 12 days’ (12 days in the future) $ date -R –date=”-14 days” (14 days in the past) What if you have Solaris “date”, then you need the below. Let’s say we need to calculate yesterday’s date. This script is for Solaris only, and it Full Article…