Results 1 to 8 of 8

Thread: Environment Variable explained...

  1. #1
    Join Date
    Aug 2010
    Beans
    3

    Environment Variable explained...

    Hi folks

    I think I need abit of help with environment variables
    Basically I have a command (ncmpcpp) that I type into the terminal to load a program.

    Im looking for a way to create an Alias, for example:
    instead of typing "ncmpcpp", I could just type "music"

    Following this, is there a way of typing a command that carries out a multiplicity of other commands?
    Say, if I typed "new_directory", it would run the following
    "cd /home/ad" and then "mkdir cookies"


    Any help would be greatly appreciated!

  2. #2
    Join Date
    Mar 2008
    Location
    Cloud 9
    Beans
    1,428
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Environment Variable explained...

    You could write a bash script and the name of the script would be the command.

    By the way, welcome to the forums.
    Last edited by pastalavista; August 14th, 2010 at 07:14 PM. Reason: welcome

  3. #3
    Join Date
    Jan 2010
    Location
    No longer SoFl
    Beans
    Hidden!
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Environment Variable explained...

    alias music='ncmpcpp'

    You can add that to your ".bashrc" file. It is case sensitive.

  4. #4
    Join Date
    Jan 2010
    Location
    No longer SoFl
    Beans
    Hidden!
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Environment Variable explained...

    Open a terminal window and type
    Code:
    nano .bashrc
    scroll down until you get to the alias section. (It can go anywhere, but to keep it organized)

  5. #5
    Join Date
    Aug 2010
    Beans
    3

    Smile Re: Environment Variable explained...

    Quote Originally Posted by SoFl W View Post
    alias music='ncmpcpp'

    You can add that to your ".bashrc" file. It is case sensitive.
    Ah! thankyou so much!
    Yeah I had been oblivious to the alias function!
    So, to add multiple coammands, are these comma separated?

  6. #6
    Join Date
    Nov 2008
    Location
    S.H.I.E.L.D. 6-1-6
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Environment Variable explained...

    Quote Originally Posted by adharwood View Post
    Ah! thankyou so much!
    Yeah I had been oblivious to the alias function!
    So, to add multiple coammands, are these comma separated?
    naw. their either seperated by the "&" character (with spaces between the command and the character, or by the ";" character
    Don't waste your energy trying to change opinions ... Do your thing, and don't care if they like it.

  7. #7
    Join Date
    Jul 2007
    Location
    Austin, TX (formerly D.C)
    Beans
    359
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Environment Variable explained...

    naw. their either seperated by the "&" character (with spaces between the command and the character, or by the ";" character
    You can also use TWO "&&" characters between the commands. Each approach has subtle differences, though.

    (1) Using & characters will execute all commands IN PARALLEL, so if you want the commands to execute one after another, use some other method.

    (2) Using the && character will execute subsequent commands only if all previous commands have returned a ZERO EXIT CODE (which normally indicates "success"). Therefore, if one command errors out, all of the subsequent commands will NOT execute.

    (3) Using ; will execute all commands one after another, regardless of error codes.

    Mike

  8. #8
    Join Date
    Jan 2010
    Location
    No longer SoFl
    Beans
    Hidden!
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Environment Variable explained...

    Would defining a function work for you? Define your function inside the .bashrc file as with the alias command.

    Example:
    Code:
    function mycommand
       {
        cd /var/log
        ls -la
        cd /home/username/
        ls -la
        cd /etc/
        ls -la
        }
    Last edited by SoFl W; August 14th, 2010 at 09:08 PM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •