Hi Nigel, You shouldn't be quoting the escaped string. Due to the fact that you're quoting the $TGT, you don't need the second TGT declaration using the builtin bash regex. So, either don't quote, or don't escape the spaces...
Chris- On Thu, Jul 14, 2011 at 7:15 AM, Nigel Allen <[email protected]> wrote: > > Greetings > > I have started to write a bash script whoise first task is to find out if a > file exists. > > A typical path for this file would be: > > /home/<username>/Maildir/.My<space>Plans.<space><space><space>125 > > when I run the script I get a "no such file or directory" but when I run the > ls command from the command line it works fine. > > The script is below. When I run it I see this: > > [root@sydsrv56 bin]# sh email_sp 125 > After padding SP = ' 125' > TGT=/home/*/Maildir/.My\ Plans.\ \ \ 125 > ls: /home/*/Maildir/.My\ Plans.\ \ \ 125: No such file or directory > > But when I run the same thing from the command line thus: > > [root@sydsrv56 bin]# ls -ld /home/*/Maildir/.My\ Plans.\ \ \ 125 > lrwxrwxrwx 1 davidt davidt 27 Apr 17 2010 /home/davidt/Maildir/.My Plans. > 125 -> /home/plans/Maildir/. 125 > > Would someone like to stop me from pulling my hair out? > > TIA > > Nigel. > > > # Usage: email_sp Strataplan [User1] [User2] > # > # Can be used for three purposes. > # > # 1. Only a Strata Plan Number is supplied. > # In this case we look for a symlink in any user's > home/Maildir folder > # and display what we find > # > # 2. For a brand new plan (Only one user supplied): > # Creates a symlink to the manager's Maildir folders under "My > Plans" > # > # 3. For a transfer from one manager to another (Two users supplied) > # In this case it needs to copy the symbolic link from one > user's Maildir to > # another, chown the symlink (-h), remove from the first > user's subscriptions > # and insert into the subscriptions file of the recipient. > # > > function usage(){ > echo "Usage: $0 spno [user1] [user2]" > exit 1 > } > > > function display_sp(){ > > PTH="/home/*/Maildir/.My Plans." > TGT=${PTH}$SP > TGT=${TGT// /\\ } > DEBUG echo "TGT="$TGT > ls -ld "$TGT" > return > } > > function new_sp() { > return > } > > function transfer_sp(){ > return > } > > function DEBUG() > { > [ "$_DEBUG" == "on" ] && $@ > } > > _DEBUG="on" > > # Did we get the correct number of arguments? > > [[ $# -eq 0 || $# -gt 3 ]] && usage > > SP=`printf "%6s" "$1"` # pad the input strata plan to 6 > characters with spaces so "125" becomes " 125" > > DEBUG echo "After padding SP = '$SP'" > > if [ $# -eq 1 ] > then > display_sp > elif [ $# -eq 2 ] > then > FR=$2 > new_sp > elif [ $# -eq 3 ] > then > TO=$3 > transfer_sp > fi > > -- > SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ > Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html > -- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
