I want to build a loop in my shell script where i run over all arguments in reverse order and use them in a command. How can this be done?
My specific code would be:
#!/bin/sh
for MODULE in "$@"
do
rmmod $MODULE
done
for MODULE in "$@"
do
insmod $MODULE
done
dmesg -c
but i want the "insmod" in the second for-loop to be called with the arguments from last to first instead.
#!/bin/sh, or are you assuming that you'll be usingbash?"$@", or to use a C-styleforloop, but/bin/shdoesn't necessarily support either.echo $SHELLon the device i want to run this, i get/bin/shas answer/bin/bashexists you can (and should) use it in scripts by changing the shebang line to#!/bin/bash. Then you get access to many more features./bin/bashdoes not exist, thanks for clarifying