The shell's flexibility makes it hard to make a good general-purpose dry-run function. You can embed things that modify or execute things inside parameters as easily as anywhere else, so your method -- and most methods -- won't work in situations like these:
Code:
# command1 and command2 will still be executed
$PREVIEW grep needle haystack | command1 | command2
# command4 will still execute
$PREVIEW command3 `command4`
# N will still be incremented
$PREVIEW echo $((N++))
One way to do it may be to embed code in a here-document. There'd be a a lot of fiddly escaping involved to prevent variables and backticks from still evaluating right at runtime.
Code:
TMP=`mktemp`
# Open FD 5 writing to temp file
exec 5>"$TMP"
# Open FD 6 reading from temp file
exec 6<"$TMP"
# Delete temp file. FD 5 and 6 will remain valid until closed.
rm "${TMP}"
cat <<EOF >&5
# This won't run at all
grep needle haystack | command1 | command2
# command4 will still execute
command3 `command4`
# command4 won't execute
command3 \`command4\`
# N will still be incremented
echo $((N++))
# N will not be incremented
echo \$((N++))
EOF
if [[ "${DRY_RUN}" == "Y" ]]
then
# Just print the contents of the temp file to the screen
cat <&6
else
# Execute the script inside a new shell
bash <&6
fi
Last edited by Corona688; 05-28-2010 at 01:59 PM..
I am new to UNIX , Can any one let me know how to execute shell script (i.e which command I have to use for the same).
Any help would be appreciated.
Thanks
siva
mymvs999@yahoo.com (3 Replies)
Hi all,
I am begginer of UNIX . I dont know if i have a script written in korn shell with .ksh extention . If i want to execute that how can i do that? Can anybody suggest the best book to learn korn shell scripting.
Thanks
sam71 (1 Reply)
Hi all,
I am beginner in UNIX...I want to use unix shell script to create text.file...I know how to use using by command...can anybody tell me for the script?
Thanks
i changed the threads title from "tex file" to "text file", because "tex" would probably be misunderstood as reference to... (4 Replies)
i want use ssh on the host01 to execute autoexec.sh on the host02 like following :
host01> ssh host02 autoexec.sh
autoexec.sh include nohup command like follwing :
nohup /home/jack/deletedata.sh &
after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Hi all,
As i want to know how the shell command "nohup" worked.I logged in as the user named vincent through Gnome.Then i press ctrl+atl+F1 changed into a console and logged in as another user named kinsley.The user "kinsley" is added by me with "useradd",and now there's no HOME directory for... (6 Replies)
Can anyone help me with a dos batch script to execute a shell script residing in an unix server. I am not able to use ssh.
Thanks in advance (2 Replies)
Hi Experts,
I want to execute shell script(on HP-UX) wihout specifying interpreter.
For e.g generally we use following command to execute shell
sh test.sh
but I want to execute it as
test.sh
currently if I execute directly it as test.sh it is giving error Commnd Not... (7 Replies)
I have a master shell script master.sh which will invoke 2 shell scripts (test1.sh,test2.sh). Both of these shell scripts will
execute stored procedure. I will invoke test1.sh, test2.sh respectively. Now both of these scripts are executing parallel.
But i want to invoke the 2nd script(test2.sh)... (3 Replies)
Hi team,
My requirement is to transfer pdf files from windows machine to unix server and then from that unix server we should sftp to another server.
I have completed the first part i.e From windows to using to unix server with the help of psftp.exe
code:
psftp user@host -pw password <... (1 Reply)
Discussion started by: bhupeshchavan
1 Replies
LEARN ABOUT PHP
mb_strstr
MB_STRSTR(3) 1 MB_STRSTR(3)mb_strstr - Finds first occurrence of a string within anotherSYNOPSIS
string mb_strstr (string $haystack, string $needle, [bool $before_needle = false], [string $encoding = mb_internal_encoding()])
DESCRIPTION mb_strstr(3) finds the first occurrence of $needle in $haystack and returns the portion of $haystack. If $needle is not found, it returns
FALSE.
PARAMETERS
o $haystack
- The string from which to get the first occurrence of $needle
o $needle
- The string to find in $haystack
o $before_needle
- Determines which portion of $haystack this function returns. If set to TRUE, it returns all of $haystack from the beginning to
the first occurrence of $needle (excluding needle). If set to FALSE, it returns all of $haystack from the first occurrence of
$needle to the end (including needle).
o $encoding
- Character encoding name to use. If it is omitted, internal character encoding is used.
RETURN VALUES
Returns the portion of $haystack, or FALSE if $needle is not found.
SEE ALSO stristr(3), strstr(3), mb_stristr(3).
PHP Documentation Group MB_STRSTR(3)