Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


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

Rep: Reputation: 0
multiple commands assigned to bash variable


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

$ pwd

$ A="pwd"
$ $A

$ pwd;pwd

$ 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, 02:34 AM   #2
Registered: Jul 2006
Location: Louisville, KY
Distribution: Fedora 12, Slackware, Debian, Ubuntu Karmic, FreeBSD 7.1
Posts: 443
Blog Entries: 1

Rep: Reputation: 47
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:

function A()
can be executed ...

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

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
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, 07:40 AM   #4
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 05:11 AM
assigning commands to a variable aunquarra Linux - General 5 01-04-2006 08:58 AM
bash, how to get variable name from variable Duudson Programming 6 01-06-2005 05:38 PM
Using Multiple Domains With An Assigned IP Space Stevegop Linux - Networking 1 10-02-2004 09:07 AM
Variable with bash pinkysioux Programming 6 04-15-2004 09:46 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:01 AM.

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