-   Linux - General (
-   -   Test script before actually running it (

Dman58 02-28-2013 07:08 AM

Test script before actually running it
As I journey through learning more Linux & writing simple bash scripts to do everyday simple tasks I find myself intimidated sometimes by the unknown. Unknown being "what the heck is this script & or command really going to do?"

I've read in the past or at least that's what I interpreted that the "echo" command could be used in order to sample the output of a command before it's actually executed. Sometimes things need to be done with root privileges but I don't want to risk doing something stupid and irreversible to compromise my system.

How would this be done? A sort of dry run that will go through the command without actually executing it? I was looking at the "test" command but that doesn't seem to fit the bill or maybe I'm wrong.

unSpawn 02-28-2013 07:48 AM

As for "--dry-run" that kind of depends but 'man bash' shows there's a switch for it except "--dry-run" means your script won't do much. "Debugging" by setting "set -Cvxe" on the CLI or running the script as say '/bin/bash -Cvxe /path/to/script' or changing the hashbang line to read "/bin/bash -Cvxe" sets noclobber, verbose and error mode which may help. Most of the time you'll only use "-vx" to see what variables get assigned etc, etc. Stuff will bite you one or more times but that's what practicing is about. As long as you don't violate the first rule (never test scripts as root account user) and as long as you make backups you should be OK.

Dman58 02-28-2013 08:27 AM

Ok I feel a bit better now. In essence that's what I've been doing but in simpler form just using the '-v' option or even multiple -v's if the program supports it. I guess it's mainly practice makes perfect (very good) in order to keep the ball rolling. What I'll do now is continue what I've already implemented and add to it in order to further improve my Linux debugging/troubleshooting knowledge.

& no I don't play around in root land because things can get pretty interesting pretty quickly.

Thanks unSpawn for the fast response.

All times are GMT -5. The time now is 09:33 AM.