Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
Hi All, I started doing linux recently. Now, I want to run my firefox with playing mplayer simultaneously. For that I did; 1. Added 1 line in /etc/bashrc as : ...
  1. #1
    Linux Newbie imranka's Avatar
    Join Date
    Dec 2007
    Location
    Kolkata
    Posts
    177

    adding environmental variable in bashrc

    Hi All,

    I started doing linux recently. Now, I want to run my firefox with playing mplayer simultaneously. For that I did;

    1. Added 1 line in /etc/bashrc as :
    > cat>> bashrc
    mybrowse='firefox & mplayer ~/im/Music/Guitar/ *.mp3'

    2. then i export the variable as:
    > export mybrowse

    but, it seems, bash can't find that command. can me help me out where I'm wrong. I'm confused about the part of exporting mostly.

    Thanks in advance,
    im

  2. #2
    Blackfooted Penguin daark.child's Avatar
    Join Date
    Apr 2006
    Location
    West Yorks
    Posts
    4,344
    You are trying to setup an alias which you should do by editing ~/.bashrc and putting
    Code:
    alias mybrowse='firefox && mplayer ~/im/Music/Guitar/ *.mp3'
    After that you need to logout of the terminal and back in again for the alias to be recognised. An alternative would be to log into a new terminal.

  3. #3
    Linux Newbie imranka's Avatar
    Join Date
    Dec 2007
    Location
    Kolkata
    Posts
    177
    Thanks a lot daark.child. I got the idea about alias. Now, if I want to this alias to work sysem wide, what I have to do? And, can you kindly give an example of setting environmental variable in /etc/bashrc and when and how to export?
    thanks in advance
    im

  4. #4
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    Quote Originally Posted by daark.child View Post
    You are trying to setup an alias which you should do by editing ~/.bashrc and putting
    Code:
    alias mybrowse='firefox && mplayer ~/im/Music/Guitar/ *.mp3'
    After that you need to logout of the terminal and back in again for the alias to be recognised. An alternative would be to log into a new terminal.
    There is no need to logout of the terminal. You could simply type "bash"
    Linux User #453176

  5. #5
    Blackfooted Penguin daark.child's Avatar
    Join Date
    Apr 2006
    Location
    West Yorks
    Posts
    4,344
    Environmental variables should be placed in /etc/profile or a users ~/.bash_profile. Its as simple as doing something like
    Code:
    export VARIABLE=SOMEVAR
    If the variable already exists and you just want to append something to it, you can do something like
    Code:
    export VARIABLE=$VARIABLE:SOMEVAR
    As for the alias to be system wide, you can put it in /etc/bashrc (path may differ on some distros).

  6. #6
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by Kieren View Post
    There is no need to logout of the terminal. You could simply type "bash"
    Better "exec bash", so the previous bash session is closed and doesn't stay behind wasting your ram.

    Quote Originally Posted by daark.child View Post
    Environmental variables should be placed in /etc/profile or a users ~/.bash_profile. Its as simple as doing something like
    Code:
    export VARIABLE=SOMEVAR
    If the variable already exists and you just want to append something to it, you can do something like
    Code:
    export VARIABLE=$VARIABLE:SOMEVAR
    As for the alias to be system wide, you can put it in /etc/bashrc (path may differ on some distros).
    Well, some distros might have some init files to put this kind of stuff on, but the files for bash should be the same always (unless a given distro patches it, of course).

    It's all in the bash man page, but to sum it up:

    Bash has many ways to be run: interactive-login, interactive non-login, and non-interactive modes.

    The modes we are concerned about are mainly the two interactive modes.

    The interactive-login mode if the mode you enter when, let's say, you login into a console (or when you invoke bash --login). In this mode, bash always sources the files /etc/profile. Then, one, and only one of these, is sourced (the first to be found, and in this order):

    ~/.bash_profile
    ~/.bash_login
    ~/.profile

    So, beware that, if you have a ~/.bash_profile, all the stuff in ~/.bash_login and ~/.profile will be discarded, even if it's an empty file.

    When we use non-login interactive sessions (e.g., when you open an xterm), the only file that is sourced is ~/.bashrc, if you look at the bash man page.

    But in my experience, /etc/bash/bashrc is also sourced in this case.

    What I do, personally, if to forget about /etc/profile, because on each update of bash it will be overwritten.

    You should look if your distro has some init file where to put global stuff. In gentoo it can be into /etc/conf.d/local.{start,stop}

    About bash, I just use ~/.bashrc and ~/.bash_profile. One of them is a symlink to the other, so I have assured that my bashrc stuff will run no matter which kind of bash session I am using. There are some quircks that you might need to work around if you find concrete problems (after all, both files are not the same by default for a reason).

  7. #7
    Blackfooted Penguin daark.child's Avatar
    Join Date
    Apr 2006
    Location
    West Yorks
    Posts
    4,344
    Well, some distros might have some init files to put this kind of stuff on, but the files for bash should be the same always (unless a given distro patches it, of course).
    They should be, but some distros change things e.g. on Debian, there is /etc/bash.bashrc instead of /etc/bashrc like most distros.

  8. #8
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by daark.child View Post
    They should be, but some distros change things e.g. on Debian, there is /etc/bash.bashrc instead of /etc/bashrc like most distros.
    If a given distro is smart enough to patch that, they should also be smart enough to patch the man page, so it's consistent. So, that's the first thing we should check.

  9. #9
    Linux Newbie imranka's Avatar
    Join Date
    Dec 2007
    Location
    Kolkata
    Posts
    177
    Ok, Now I have plenty of problems that I can't sort out myself. hope you'll bear with and guide me thru, as I deeply need it in my early learning stage. i'll describe what I did and what is the result I got:

    1> In ~/.bashrc I added this line:
    mybrowse=firefox & mplayer /home/Imran/Music/ *.mp3;
    export mybrowse
    Now everytime i'm opening a terminal this is coming:
    MPlayer 1.0rc2-4.1.2 (C) 2000-2007 MPlayer Team
    CPU: Intel(R) Core(TM)2 Duo CPU E4500 @ 2.20GHz (Family: 6, Model: 15, Stepping: 13)
    CPUflags: MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
    Compiled with runtime CPU detection.
    mplayer: could not connect to socket
    mplayer: No such file or directory
    Failed to open LIRC support. You will not be able to use your remote control.

    Playing /home/Imran/Music/.
    Win32 LoadLibrary failed to load: avisynth.dll, /usr/lib/codecs/avisynth.dll, /usr/lib/win32/avisynth.dll, /usr/local/lib/win32/avisynth.dll
    Seek failed


    Playing *.mp3.
    File not found: '*.mp3'
    Failed to open *.mp3.
    2> I typed $PATH in terminal and this is coming:
    bash: /usr/kerberos/bin:/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/Imran/bin: No such file or directory
    Then I added bin directory under /home/Imran/. But still the same message is showing.
    Similarly, I typed $PATH as root doing su -. There this is showing:
    -bash: /usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin: No such file or directory
    Again, I added a directory bin there, but still the same problem. I know there must be some problem with my understanding, but this is so frustating I can't help the grunt.

    Kindly show me the way.

    im

  10. #10
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047
    There is no need to log out and in again when you edit .bashhrc. Just type >source .bashrc< and it rereads the file.

    To add an alias you don´ t need to export it. Just:
    Code:
    alias mybrowse='command_1 command_2 option'
    Then source ~/.bashrc and you're done.
    Can't tell an OS by it's GUI

Page 1 of 2 1 2 LastLast

Posting Permissions

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