Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Systems > Linux / BSD / OS X
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 12-12-2005, 07:58 AM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
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?
__________________
sde is offline   Reply With Quote
Old 12-12-2005, 10:42 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
answer: ${mypath}admin
__________________
sde is offline   Reply With Quote
Old 12-12-2005, 11:31 AM   #3 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
redhead is on a distinguished road
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.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 12-12-2005, 11:37 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
ah yeah, .. it's easy to forget all the different shells. i use sh pretty much exclusively for this stuff.
__________________
sde is offline   Reply With Quote
Old 12-12-2005, 12:29 PM   #5 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
redhead is on a distinguished road
In sh it should be as simple as: "$mypath"admin since it produces the same as ${mypath}admin
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 12-12-2005, 12:38 PM   #6 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,114
Belisarius is on a distinguished road
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.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 12-12-2005, 09:04 PM   #7 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 595
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
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
teknomage1 is offline   Reply With Quote
Old 12-12-2005, 11:51 PM   #8 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
redhead is on a distinguished road
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.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 12-13-2005, 05:25 PM   #9 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,114
Belisarius is on a distinguished road
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.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 12-13-2005, 06:59 PM   #10 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 595
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
Yeah, there's a surprizing amount of stuff around here from '87 when the studio was founded.
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if variable is empty or is not set. jcpp MS Technologies ( ASP, VB, C#, .NET ) 1 06-20-2005 08:48 AM
Weird Image Scrolling Script...Please Help mark4man HTML, XML, Javascript, AJAX 3 06-14-2005 07:51 AM
reset Variable in HTML awieds MS Technologies ( ASP, VB, C#, .NET ) 2 04-11-2005 11:32 PM
What is a shell variable in UNIX Shell Script rakesh Linux 0 08-31-2004 08:25 AM
shell script for ftp Hrqls Linux / BSD / OS X 7 09-20-2002 03:14 AM


All times are GMT -8. The time now is 11:03 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle