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 Mar 23, 2006 | 08:06 PM
  #1  
Markus's Avatar
Markus
Thread Starter
Scooby Regular
25 Year Member
 
Joined: Mar 1999
Posts: 25,080
Likes: 0
From: The Great White North
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
Reply
Old Mar 23, 2006 | 08:21 PM
  #2  
jpor's Avatar
jpor
Scooby Regular
iTrader: (1)
 
Joined: Sep 2003
Posts: 3,109
Likes: 0
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!
Reply
Old Mar 24, 2006 | 07:05 PM
  #3  
Markus's Avatar
Markus
Thread Starter
Scooby Regular
25 Year Member
 
Joined: Mar 1999
Posts: 25,080
Likes: 0
From: The Great White North
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?
Reply
Old Mar 24, 2006 | 09:47 PM
  #4  
stevem2k's Avatar
stevem2k
Scooby Regular
 
Joined: Sep 2001
Posts: 4,670
Likes: 0
From: Kingston ( Surrey, not Jamaica )
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...
Reply
Old Mar 25, 2006 | 01:51 AM
  #5  
Markus's Avatar
Markus
Thread Starter
Scooby Regular
25 Year Member
 
Joined: Mar 1999
Posts: 25,080
Likes: 0
From: The Great White North
Default

Thanks chaps. I'll give it a shot.
Reply
Old Mar 25, 2006 | 08:36 AM
  #6  
GaryCat's Avatar
GaryCat
Scooby Regular
 
Joined: Apr 1999
Posts: 2,044
Likes: 0
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`
Reply
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
Nov 4, 2021 07:12 PM
Abx
Subaru
22
Jan 9, 2016 05:42 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
28
Dec 28, 2015 11:07 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
12
Nov 18, 2015 07:03 AM
Brzoza
Engine Management and ECU Remapping
1
Oct 2, 2015 05:26 PM




All times are GMT +1. The time now is 12:22 PM.