[Gllug] Bash Question - My Brain's not working tonight

Ken Smith kens at kensnet.org
Mon Aug 27 07:16:57 UTC 2007


Alain Williams wrote:
> On Sun, Aug 26, 2007 at 10:07:09PM +0100, Ken Smith wrote:
>   
>> Hi, I writing a simple backup script with bash. But my string 
>> programming is all messed up - I'm really inexperienced in this area. 
>> The script is to use rsync to backup a CIFS share from a Win box.
>>
>> I want to check to see if  the share is already mounted for whatever 
>> reason.
>>
>> I have the machine name in $1 and the share name is $2
>>
>> so what I want to do is
>>
>> mount | grep //$1/$2 and then use an if statement based on the value of $?
>>
>> where in this case
>>
>> $1 is trh2003.trhbeith.local
>>
>> and $2 is e$
>>
>> and the whole string I'm looking for in the mount output is 
>> //trh2003.trhbeith.local/e$
>>
>> But somehow the "/'s" are getting mashed somewhere.
>>     
>
> Put
> 	set -x
> on the line before -- shell debugging, see what is being substituted/executed.
> Note that the RE:
> 	//trh2003.trhbeith.local/e$
> has some meta characters in it:
>
> 	.	-- match anything, probably benign
> 	$	-- match end of string
>
> The $ will cause problems since it says: 'find an 'e' at the end of line'
> which is not what you want.
>
> You could try something like:
>
> 	mount | grep -q "$( echo "//$1/$2" | sed -e 's/\$/\\$/g' )"
>
> The -q is there because you don't want to see what it finds.
>
>   
Thank you, that worked. I need to re-read the man page on sed

:-)

Ken

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list