LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   multiple commands assigned to bash variable (http://www.linuxquestions.org/questions/linux-newbie-8/multiple-commands-assigned-to-bash-variable-528875/)

itzamecwp 02-14-2007 01:00 AM

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.

bartonski 02-14-2007 02:34 AM

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


acid_kewpie 02-14-2007 02:34 AM

that's a pretty nasty way of simplifying things... why aren't you using alias? that's exactly what it's for.

itzamecwp 02-14-2007 07:40 AM

Yup! alias did the trick.

Thank you both for such quick relies.


All times are GMT -5. The time now is 09:02 PM.