Comentários (3)

1 AnthonyEnglish comentou às Link permanente

Another great post, Brian! <div>&nbsp;</div> I always do this when writing a new script - echo the commands rather than run them. In fact, I go one further: you can set a debug flag at the beginning of the script. All it does is run the command "echo". If $DEBUG is set, you get a print of all the commands you're going to run. If it's not set, then the commands actually get run. <div>&nbsp;</div> Here's how I'd call the script: <br /> myscript.sh echo <br /> and then inside the script, if there is an argument passed to the script, the DEBUG variable is set to echo: <div>&nbsp;</div> if [ -n "$1" ] <br /> then <br /> DEBUG=$1 <br /> fi <div>&nbsp;</div> You can change the above syntax to use getopts instead, for example. <div>&nbsp;</div> $DEBUG lsdev -cadapter <div>&nbsp;</div> If DEBUG is set to "echo" the above command is: <br /> echo lsdev -cadapter <br /> in other words, just display the command. <br /> if DEBUG is not set, then the above command line becomes: <div>&nbsp;</div> lsdev -cadapter <div>&nbsp;</div> so it actually runs the lsdev command, rather than just displaying it. <div>&nbsp;</div> There are lots of ways you can enhance this but the idea is that you can call the script either doing something or just displaying the commands. <div>&nbsp;</div> Incidentally, most people run the lsdev command with the -C flag (e.g. lsdev -Cc adapter), but the -C flag is not required. It's there for backward compatibility with earlier versions of AIX.

2 brian_s comentou às Link permanente

Anthony, thanks for the great suggestion! That is a very good way to do it.

3 jeffschaller42 comentou às Link permanente

Great stuff, Brian! I'm also a big fan of the "dry run" or "not really" flag, like rsync's -n. The things you learn the hard way :)