Re: bash shell script questions
David Stern wrote: [snip] > > You should use '#!/bin/bash' really, because now sh is just a link > > to bash, but you are not guaranteed that in a future version it will > > be another shell, or that bash _will_ act more (dumb) Bourne like in > > the future when called as 'sh' (I for one would appreciate it). > > Noted. However I thought that /bin/sh was more "un*x-compatible", thus > more extensible across other platforms where bash may not be available, > therefore making /bin/sh preferred. True?/Not true? > > (When, if ever, do you think use of /bin/sh is appropriate?) You should use hashpling with /bin/sh if you are sure that your script is _bourne_ compatible. echo -e is not. Another example I stumbled upon is that redirection and piping in a bourne shell is done within a subshell. Any posix shell (bash, ksh) will do it in the current shell. So something like: while read VAR ; do eval ARR${COUNT}=${VAR} COUNT=`expr $COUNT + 1` done < foo echo $ARR1 will assign a value to ARR1, ARR2 etc out of the file foo, when using a posix shell. Bourne will not keep the value, because the assignment is done in a subshell. If you do not have any of those diffs in your script, use #!/bin/sh, else use #!/bin/bash. (MHO) HTH, Rob. -- Rob S. Wolfram[EMAIL PROTECTED][EMAIL PROTECTED] W3: http://www.mcs.nl/~rsw http://www.wi.leidenuniv.nl/~rwolfram PGP: 768/07606049 31 09 D2 D7 57 B4 F4 FC CA FC 1F 34 8C BA C8 56 -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED] .
Re: bash shell script questions
On Fri, 09 Jan 1998 23:01:54 +0100, "Rob S. Wolfram" wrote: > David Stern wrote: >>[..] > news://comp.unix.shell I know now. > > 1.) How do I insert a newline character in a "double-quoted" string? > If you mean "when using bash's built-in echo command", use > echo -e "Test\nMoreText" I'll use that in the future. > > 2.) What is a good method to reassign variables interactively? > read VAR Got it, thanks. > > #!/bin/sh > You should use '#!/bin/bash' really, because now sh is just a link > to bash, but you are not guaranteed that in a future version it will > be another shell, or that bash _will_ act more (dumb) Bourne like in > the future when called as 'sh' (I for one would appreciate it). Noted. However I thought that /bin/sh was more "un*x-compatible", thus more extensible across other platforms where bash may not be available, therefore making /bin/sh preferred. True?/Not true? (When, if ever, do you think use of /bin/sh is appropriate?) > > echo "" ; echo "David's BackupUtility v. 0.1." ; echo "" ; > > while [ $option -ne 7 ] > Do surround vars in a test in double quotes, to protect the empty > string, like in: while [ "$option" -ne 7 ] Noted. Thankyou very much. > > echo " Copy method is $copymethod" > > ; echo "" ; > ^ I suppose this belongs to the last line? I set email linewrap to 72, but allowed a few more in my code. > > read option > > case $option in > > 1) > > echo " Change source list." > > echo " How do I interactively reassign \$dbu_list ?" ; echo "" ; > read dbu_list > Or maybe you want to use another var, test its validity and eventually > reassign your old one with $SECONDVAR ? Exactly. Immediately following the original post, a number of thoughts I was having formed ideas, which dawned some realizations and I haven't really mapped out where I want to take this, because some of my ideas will require more error handling than I think is suited for a bash script. Fortunately, I got it to work and added a few of my ideas, so it works well enough to pass proof test, which allows me to use it a little and see how I'd like it to develop. > Politically biassed advice: man cpio Although I'm not intimate with cpio yet, that's the agenda. In any event, my default copy method (safecopy2) implements cpio. I've intentionally made this modular so I don't have do any deathly hacking should I decide to make any changes. Thanks to you all, it works pretty well. :-) I more or less figure this is amateur code, but it works pretty well, so if anyone wants to use or mangle it, feel free to have a go at it. :-) <<< message/external-body; name="/home/share/bin/safecopy2"; access-type=LOCAL-FILE; site="localhost.localdomain": Unrecognized >>> <<< message/external-body; name="/home/share/bin/dbu"; access-type=LOCAL-FILE; site="localhost.localdomain": Unrecognized >>> David Stern [EMAIL PROTECTED] http://weber.u.washington.edu/~kotsya/
Re: bash shell script questions
David Stern wrote: > I know this isn't a bash shell script news group, but the fact is I > can't find one. Since bash is the default linux shell, I was hoping news://comp.unix.shell > someone could answer a few pretty simple questions. > > 1.) How do I insert a newline character in a "double-quoted" string? If you mean "when using bash's built-in echo command", use echo -e "Test\nMoreText" > > 2.) What is a good method to reassign variables interactively? read VAR [snip] > #!/bin/sh You should use '#!/bin/bash' really, because now sh is just a link to bash, but you are not guaranteed that in a future version it will be another shell, or that bash _will_ act more (dumb) Bourne like in the future when called as 'sh' (I for one would appreciate it). > # David's Backup Utility (dbu) v. 0.1 > # David Stern <[EMAIL PROTECTED]> > # Tue Jan 6 15:31:01 PST 1998 > > dbu_list=/root/dbu_list > destination=/backup2 > device=/dev/sdb2 > copymethod=safecopy2 > option=0 > > echo "" ; echo "David's Backup Utility v. 0.1." ; echo "" ; > while [ $option -ne 7 ] Do surround vars in a test in double quotes, to protect the empty string, like in: while [ "$option" -ne 7 ] > do > echo " Select a backup operation " > echo " " > echo " 1. Change source list." > echo " 2. Change backup destination base directory. " > echo " 3. Change backup device. " > echo " 4. Change copy method." > echo " 5. Format backup destination device. " > echo " 6. Backup selected files to $destination. " > echo " 7. Quit. " > echo " " > echo " Source list is $dbu_list " > echo " Destination directory is $destination " > echo " Backup device is $device " > echo " Copy method is $copymethod" > ; echo "" ; ^ I suppose this belongs to the last line? > read option > case $option in > 1) > echo " Change source list." > echo " How do I interactively reassign \$dbu_list ?" ; echo "" ; read dbu_list Or maybe you want to use another var, test its validity and eventually reassign your old one with $SECONDVAR ? > ;; > 2) > echo " Change backup destination base directory." > echo " How do I interactively reassign \$destination ?" ; echo > "" ; > ;; > 3) > echo " Change backup device." > echo " How do I interactively reassign \$device ?" ; echo "" ; > ;; > 4) > echo " Change copy method." > echo " How do I interactively reassign \$copymethod ?" ; echo > "" ; > ;; > 5) > echo " Format backup destination directory." ; echo "" ; > # mke2fs -v $device > ;; > 6) > echo " Backup selected files to $destination ." > for source in `cat $dbu_list` > do > if [ -d $destination$source ] # helper > then > echo " $destination$source exists." > else > echo " $destination$source does not exist." > # mkdir $destination$source > fi > echo " $copymethod $source ... $destination$source" ; echo > "" ; > # $copymethod $source $destination$source > ##echo "" ; echo "ls $source"; echo " ; ls $source ; > done > ;; > esac > done Politically biassed advice: man cpio Cheers, Rob -- Rob S. Wolfram[EMAIL PROTECTED][EMAIL PROTECTED] W3: http://www.mcs.nl/~rsw http://www.wi.leidenuniv.nl/~rwolfram PGP: 768/07606049 31 09 D2 D7 57 B4 F4 FC CA FC 1F 34 8C BA C8 56 -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED] .
Re: bash shell script questions
On Wed, 07 Jan 1998 21:27:01 +1030, John Spence wrote: > > I know this isn't a bash shell script news group, but the fact is I > > can't find one. Since bash is the default linux shell, I was hoping > > someone could answer a few pretty simple questions. > > Hi David. > > Try this link for an intro to Bourne shell scripts. > > http://riceinfo.rice.edu/Computer/Documents/Classes/Unix/bourne/bourne.html > > There's lots of other good info on that site too BTW. > > -- > John Spence <[EMAIL PROTECTED]> http://www.newave.net.au/~jspence That's a very thorough tutorial. Thanks! :-) I got my answer to the most important question (reassigning variables interactively) here first. You're also right that there are some other good unix docs there. Thanks again! :-) -- David Stern [EMAIL PROTECTED] http://weber.u.washington.edu/~kotsya/ -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED] .
Re: bash shell script questions
On Tue, 6 Jan 1998, David Stern wrote: > Hi, > > I know this isn't a bash shell script news group, but the fact is I > can't find one. Since bash is the default linux shell, I was hoping > someone could answer a few pretty simple questions. > > 1.) How do I insert a newline character in a "double-quoted" string? echo -ne "hello \n world" (Try it, you may want it without the -n, but -e is necessary) > 2.) What is a good method to reassign variables interactively? echo -n "what copy method: " read copy_method [ 3rd question and script snipped ] My own scripting question: How do I changed the command's appearence to ps? E.g. sendmail identifies that it is accepting connections. I'd like my scripts to say what part of the compile it's working on. HTH and TIA, Brandon - Brandon Mitchell <[EMAIL PROTECTED]> "We all know linux is great... it PGP: finger -l [EMAIL PROTECTED] does infinite loops in 5 seconds" Phone: (757) 221-4847 --Linus Torvalds -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED] .
Re: bash shell script questions
> I know this isn't a bash shell script news group, but the fact is I > can't find one. Since bash is the default linux shell, I was hoping > someone could answer a few pretty simple questions. Hi David. Try this link for an intro to Bourne shell scripts. http://riceinfo.rice.edu/Computer/Documents/Classes/Unix/bourne/bourne.html There's lots of other good info on that site too BTW. -- John Spence <[EMAIL PROTECTED]> http://www.newave.net.au/~jspence -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED] .
bash shell script questions
Hi, I know this isn't a bash shell script news group, but the fact is I can't find one. Since bash is the default linux shell, I was hoping someone could answer a few pretty simple questions. 1.) How do I insert a newline character in a "double-quoted" string? 2.) What is a good method to reassign variables interactively? 3.) [not really part of my shell script..] Is there a way to "scroll" within the "Ctrl-r" history file search? (e.g.: let's say I type "Ctrl-r" "filename" and the first thing that comes up is "ls -l filename", but I want the previous one when I typed "filename -param1 -param2". What key sequence can I use to scroll to the previous use of "filename") I'll include my shell script so you have some idea of what I'm trying to do. Try not to laugh too hard, I'm sensitive about my code. :-) BTW: I'm a fairly inexperienced shell script writer, so I'd also appreciate any helpful remarks. - #!/bin/sh # David's Backup Utility (dbu) v. 0.1 # David Stern <[EMAIL PROTECTED]> # Tue Jan 6 15:31:01 PST 1998 dbu_list=/root/dbu_list destination=/backup2 device=/dev/sdb2 copymethod=safecopy2 option=0 echo "" ; echo "David's Backup Utility v. 0.1." ; echo "" ; while [ $option -ne 7 ] do echo " Select a backup operation " echo " " echo " 1. Change source list." echo " 2. Change backup destination base directory. " echo " 3. Change backup device. " echo " 4. Change copy method." echo " 5. Format backup destination device. " echo " 6. Backup selected files to $destination. " echo " 7. Quit. " echo " " echo " Source list is $dbu_list " echo " Destination directory is $destination " echo " Backup device is $device " echo " Copy method is $copymethod" ; echo "" ; read option case $option in 1) echo " Change source list." echo " How do I interactively reassign \$dbu_list ?" ; echo "" ; ;; 2) echo " Change backup destination base directory." echo " How do I interactively reassign \$destination ?" ; echo "" ; ;; 3) echo " Change backup device." echo " How do I interactively reassign \$device ?" ; echo "" ; ;; 4) echo " Change copy method." echo " How do I interactively reassign \$copymethod ?" ; echo "" ; ;; 5) echo " Format backup destination directory." ; echo "" ; # mke2fs -v $device ;; 6) echo " Backup selected files to $destination ." for source in `cat $dbu_list` do if [ -d $destination$source ] # helper then echo " $destination$source exists." else echo " $destination$source does not exist." # mkdir $destination$source fi echo " $copymethod $source ... $destination$source" ; echo "" ; # $copymethod $source $destination$source ##echo "" ; echo "ls $source"; echo " ; ls $source ; done ;; esac done -- David Stern [EMAIL PROTECTED] http://weber.u.washington.edu/~kotsya/ -- TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to [EMAIL PROTECTED] . Trouble? e-mail to [EMAIL PROTECTED] .