Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Shell script question

Thread Tools
 
Search this Thread
 
Old 23 March 2006, 08:06 PM
  #1  
Markus
Scooby Regular
Thread Starter
 
Markus's Avatar
 
Join Date: Mar 1999
Location: The Great White North
Posts: 25,080
Likes: 0
Received 0 Likes on 0 Posts
Default Shell script question

Afternoon/Evening,
A question for those scripting types out there.

I want to have a shell script that I can pass a path to and then have add something to that path and perform an action with it. For example the command would be:

$ ./myscript /Volumes/Mac\ OS\ X/

The script would do the following:

Code:
#!/bin/sh
rm -rf "${1}/Library/NameOfFolder/"
rm -rf "${1}/Library/StartupItems/AnotherFolder/"
Now, I can issue the command as mentioned above, but it tells me that the path /Volumes/Mac does not exist, so I'm guessing it's not correctly parsing the spaces in the volume name.

What am I doing wrong, and how do I get it to work?

Thanks in advance
Old 23 March 2006, 08:21 PM
  #2  
jpor
Scooby Regular
iTrader: (1)
 
jpor's Avatar
 
Join Date: Sep 2003
Posts: 3,109
Likes: 0
Received 0 Likes on 0 Posts
Default

You need to put an if statement in to check.

Something on the lines of:

F1="${1}/Library/NameOfFolder/"
F2="${1}/Library/StartupItems/AnotherFolder/"

if [ -d ${F1} ]
then
rm ${F1}
else
echo " ${F1} not found!"
fi

if [ -d ${F2} ]
then
rm -rf ${F2}
else
echo "${F2} not found !"
fi

A breakdown of this:

declare variables F1 & F2

If -d (directroy) exists then remove

This is NOT tested as my RS6000 isn't powered up at the moment to test this little code. So worth testing 1st!
Old 24 March 2006, 07:05 PM
  #3  
Markus
Scooby Regular
Thread Starter
 
Markus's Avatar
 
Join Date: Mar 1999
Location: The Great White North
Posts: 25,080
Likes: 0
Received 0 Likes on 0 Posts
Default

Should have mentioned, the path /Volumes/Mac\ OS\ X/ does exist. I think the problem is due to the spaces in the "Mac OS X" bit of ther path name.

Guessing I need to somehow encode them, any ideas how?
Old 24 March 2006, 09:47 PM
  #4  
stevem2k
Scooby Regular
 
stevem2k's Avatar
 
Join Date: Sep 2001
Location: Kingston ( Surrey, not Jamaica )
Posts: 4,670
Likes: 0
Received 0 Likes on 0 Posts
Default

and all your backslashes that will need escaping ....

could use 'eval'
$ x="etcha\ sketch"
$ eval cd $x

export $basedir="/path/to/space in/here"

echo $basedir fails
echo "$basedir" works.....



I can't test it all as I don't have access to macs.....give it a whirl...
Old 25 March 2006, 01:51 AM
  #5  
Markus
Scooby Regular
Thread Starter
 
Markus's Avatar
 
Join Date: Mar 1999
Location: The Great White North
Posts: 25,080
Likes: 0
Received 0 Likes on 0 Posts
Default

Thanks chaps. I'll give it a shot.
Old 25 March 2006, 08:36 AM
  #6  
GaryCat
Scooby Regular
 
GaryCat's Avatar
 
Join Date: Apr 1999
Posts: 2,043
Likes: 0
Received 0 Likes on 0 Posts
Default

You need to put the args in double quotes when you call it e.g.

$ ./myscript "/Volumes/Mac\ OS\ X/"

...then it will be treated as one arg. Otherwise you could concatenate it in your script like...

var=`echo $1 $2 $3`
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
04 November 2021 07:12 PM
Abx
Subaru
22
09 January 2016 05:42 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
28
28 December 2015 11:07 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
12
18 November 2015 07:03 AM
Brzoza
Engine Management and ECU Remapping
1
02 October 2015 05:26 PM



Quick Reply: Shell script question



All times are GMT +1. The time now is 06:19 AM.