LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-14-2007, 12:00 AM   #1
itzamecwp
LQ Newbie
 
Registered: Dec 2006
Distribution: Ubuntu
Posts: 20

Rep: Reputation: 0
multiple commands assigned to bash variable


Hi,

Im tying to assign multiple commands to a variable and having
quite a hard time. Here's how it goes ..

$ pwd
/currentfolder

$ A="pwd"
$ $A
/currentfolder

$ pwd;pwd
/currentfolder
/currentfolder

$ A="pwd;pwd"
$ $A
-bash: pwd;pwd: command not found

Heh?! What am I missing here? spacing doesn't seem to help either.

Im running Ubuntu 6.06.1

Thanks in advance.
 
Old 02-14-2007, 01:34 AM   #2
bartonski
Member
 
Registered: Jul 2006
Location: Louisville, KY
Distribution: Fedora 12, Slackware, Debian, Ubuntu Karmic, FreeBSD 7.1
Posts: 443
Blog Entries: 1

Rep: Reputation: 48
I'm not absolutely sure that you can do what you're wanting to do, in the way that you're wanting to do it... the ';' character is going to terminate the current command, and I don't think that you can pack that into a variable, and then unpack it correctly. (I can't quote chapter and verse from the bash man pages, so please take that with a large grain of salt)

What you can do, which is very similar, is create a shell function:

Code:
function A()
{
pwd
pwd
}
can be executed ...

Code:
$ A
/currentdirectory
/currentdirectory
 
Old 02-14-2007, 01:34 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
that's a pretty nasty way of simplifying things... why aren't you using alias? that's exactly what it's for.
 
Old 02-14-2007, 06:40 AM   #4
itzamecwp
LQ Newbie
 
Registered: Dec 2006
Distribution: Ubuntu
Posts: 20

Original Poster
Rep: Reputation: 0
Yup! alias did the trick.

Thank you both for such quick relies.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
assigning commands to a variable aunquarra Linux - General 5 01-04-2006 07:58 AM
bash, how to get variable name from variable Duudson Programming 6 01-06-2005 04:38 PM
Using Multiple Domains With An Assigned IP Space Stevegop Linux - Networking 1 10-02-2004 08:07 AM
Variable with bash pinkysioux Programming 6 04-15-2004 08:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration