|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
|
Re: [PLUG] Easy Bash Scripting Question
|
In the message dated: Wed, 23 Dec 2009 07:45:16 EST,
The pithy ruminations from Casey Bralla on
<[PLUG] Easy Bash Scripting Question> were:
=> I've written a bash script and I find that the commands don't normally echo to
=> the screen, so I can't follow along with the script.
You want the "-x" option to bash, as in:
bash -x ./myscript
for testing, or by changing the first line in the script to:
#! /bin/bash -x
to make it permanent.
=>
=> for example:
=>
=> #!/bin/bash
=> cp file1 file2
=> mkdir /directory1
=> cd /directory1
=> rm *
Whoa! That's very risky....think of what happens if the "mkdir" or "cd"
commands fail. I've seen developers wipe out a multi-millon dollar
ecommerce site multiple times with just this kind of error. (Yes, multiple
times...they assumed it was an OS or sysadmin error, and after I restored the
server--multiple times--they kept running the same script...loads of fun.)
Before running this script, I'd strongly recommend:
changing the "rm" command to echo what it would do, as in:
echo "Would do: rm *"
learning how to check the return value of a command (the mkdir & cd),
and how to avoid doing the following operations if the command[s]
failed
Mark
=> cd ..
=>
=>
=>
=>
=>
=>
=> I'd like to know when the script is copying files, and when it is erasing files.
=>
=> I could add echo statements, but it would be much simpler if the actual bash
=> commands simply echoed to the screen.
=>
=> Is there a simple way to do this?
=>
=>
=> TIA JP!
=> --
=>
=> Casey Bralla
=> Chief Nerd in Residence
=> The NerdWorld Organisation
=>
=> http://www.NerdWorld.org
=> ___________________________________________________________________________
=> Philadelphia Linux Users Group -- http://www.phillylinux.org
=> Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
=> General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
=>
-----
Mark Bergman Biker, Rock Climber, Unix mechanic, IATSE #1 Stagehand
http://wwwkeys.pgp.net:11371/pks/lookup?op=get&search=bergman%40merctech.com
I want a newsgroup with a infinite S/N ratio! Now taking CFV on:
rec.motorcycles.stagehands.pet-bird-owners.pinballers.unix-supporters
15+ So Far--Want to join? Check out: http://www.panix.com/~bergman
___________________________________________________________________________
Philadelphia Linux Users Group -- http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
|
|