ok.. this is the deal. i have a bash script like the following. the script is only to show you what i mean .. it may look strang... but is exactly what i need.:
#/bin/bash runcommand () { message="$1" shift echo "$message" $@ > /tmp/logfile if [ $? -gt 0 ]; then cat /tmp/logfile fi } runcommandwrapper () { wrapperoptions="$1" shift $* } rm -f /tmp/test ; rm -f /tmp/logfile runcommand "echo into file" echo "SUCCESS" > /tmp/test echo "-----------------" echo "test file:" echo "-----------------" cat /tmp/test echo "-----------------" echo echo "-----------------" echo "logfile file:" echo "-----------------" cat /tmp/logfile echo "-----------------" echo echo echo rm -f /tmp/test ; rm -f /tmp/logfile runcommand "echo into file" 'echo "SUCCESS" > /tmp/test' echo "-----------------" echo "test file:" echo "-----------------" cat /tmp/test echo "-----------------" echo echo "-----------------" echo "logfile file:" echo "-----------------" cat /tmp/logfile echo "-----------------" echo this works
runcommand "running command mount" mount this does not work
runcommand "running command fdisk" fdisk > /tmp/fdiskoutput in this case the text in quotation marks is not treated as a whole argument within the wrapper script. try it, you'll see what I mean. --> SOLVED
So Running the above script returns:
----------------- test file: ----------------- echo into file ----------------- ----------------- logfile file: ----------------- SUCCESS ----------------- echo into file ----------------- test file: ----------------- cat: /tmp/test: No such file or directory ----------------- ----------------- logfile file: ----------------- "SUCCESS" > /tmp/test ----------------- but the expected outcome is:
----------------- test file: ----------------- SUCCESS ----------------- ----------------- logfile file: ----------------- ----------------- echo into file ----------------- test file: ----------------- SUCCESS ----------------- ----------------- logfile file: ----------------- ----------------- how can i pass commands with redirection or pipe lining as a command to another function in bash ?
and help and tips would be very much appreciated! I have no idea how to get this working, or if this is possible at all?