|
 |
|
 |
 |
12-12-2005, 07:58 AM
|
#1 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,397
|
shell script variable
i have a shell script where i send in a path, and then i need to append it.
Code:
mypath="/mydir/$1"
./mycommand $mypathadmin
./myshellscript /home/sde/
so basically i want the following command to run
./mycommand /home/sde/admin
but, .. my script doesn't work. how do i append a variable in a shell script? i've tried $mypath+"admin" , but that puts the + sign in there.
did that make sense?
__________________
|
|
|
12-12-2005, 10:42 AM
|
#2 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,397
|
answer: ${mypath}admin
__________________
|
|
|
12-12-2005, 11:31 AM
|
#3 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
|
Mike, next time, provide your scripting language, since some of these things are shell dependant, so if your using bash it might be a different approach than when you're using zsh/sh/csh.
|
|
|
12-12-2005, 11:37 AM
|
#4 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,397
|
ah yeah, .. it's easy to forget all the different shells. i use sh pretty much exclusively for this stuff.
__________________
|
|
|
12-12-2005, 12:29 PM
|
#5 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
|
In sh it should be as simple as: "$mypath"admin since it produces the same as ${mypath}admin
|
|
|
12-12-2005, 12:38 PM
|
#6 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,114
|
I switch between tcsh/csh (Solaris) and bash/sh (Linux), and both take the ${var} syntax.
As a rule, I always ${} my variables so my code is consistent. I strongly suggest you do the same, it saves headaches in the future (like this one). A little extra typing goes a long way in readability.
|
|
|
12-12-2005, 09:04 PM
|
#7 (permalink)
|
|
Jack of all trades
Join Date: Feb 2005
Location: Los Angeles
Posts: 595
|
Good advice, Belisarius. Lately I've been dealing with the fun of tcsh on irix boxes. The bash feature I miss most is functions. They nicely bridge that gap between too complicated for aliases and too simple for scripts.
__________________
Stop intellectual property from infringing on me
|
|
|
12-12-2005, 11:51 PM
|
#8 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
|
I allways code my scripts in pure sh, I know for some routines it requires a bit more scripting than say in bash, but no matter what *nix deriviant it is run on, you can be sure theres allways sh installed.
|
|
|
12-13-2005, 05:25 PM
|
#9 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,114
|
The problem for me is that at work, there are a great many existing scripts in csh, and most of the people that use them are used to that shell. So rather than radically deviate and start using a completely different shell, I just try to adopt clear coding styles.
|
|
|
12-13-2005, 06:59 PM
|
#10 (permalink)
|
|
Jack of all trades
Join Date: Feb 2005
Location: Los Angeles
Posts: 595
|
Yeah, there's a surprizing amount of stuff around here from '87 when the studio was founded.
__________________
Stop intellectual property from infringing on me
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 11:03 PM.
|
Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle
|
 |
|