[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

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 <kotsya@u.washington.edu>
> # 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            rsw@mcs.nl            rwolfram@wi.leidenuniv.nl
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
debian-user-request@lists.debian.org . 
Trouble?  e-mail to templin@bucknell.edu .


Reply to: