Results 1 to 4 of 4

Thread: variables in .bashrc: how to using dir path

  1. #1
    Join Date
    Aug 2009
    Beans
    91

    variables in .bashrc: how to using dir path

    Hi,

    I have what I hope is a fairly simple question to answer. In my ~/.bashrc file I can create this alias:
    Code:
    alias uChmodDP='chmod -R $1 $2' #specify permissions
    and the variables work fine. But I cannot seem to get any love from this alias:
    Code:
    alias umnt='umount /dev/$1'
    I realize the likely problem is the variable following hot on the heels of a specific directory, but is there anyway to specify a variable in an alias like this?

    For some reason I cannot umount usb pen drives by right clicking, and have to always resort to the terminal to do so, which for me is no real biggie, but if I could create this alias it would be an even better no biggie to umount using the terminal.

    Actually, the inability to right click to umount usb devices seems to be a Thunar issue since I run xubuntu. Using Nautilus I am able to right click and eject/safely remove devices. Using Thunar however, right click unmount always pukes back an error that the device must have been mounted on the command line or some such BS. But like I said it is no real biggie to use terminal, but an alias would be even nicer.

    I prefer using Thunar and Xubu most of the time b/c my laptop is quite underpowered.

    cheers,
    tt
    Last edited by thaitang; June 21st, 2011 at 04:36 AM. Reason: to add info

  2. #2
    Join Date
    Apr 2006
    Location
    Ubuntuland
    Beans
    2,124
    Distro
    Ubuntu 13.10 Saucy Salamander

    Lightbulb Re: variables in .bashrc: how to using dir path

    Read up on how bash uses single quotes and double quotes
    24 beers in a case, 24 hours in a day. Coincidence? I think not!

    Trusty Tahr 64 bit, AMD Phenom II 955 Quad Core 3.2GHz, GeForce 9600 GT
    16G PC2-6400 RAM, 128 GB SSD, Twin 1TB SATA 7200 RPM RAID0

  3. #3
    Join Date
    Jan 2008
    Location
    Manchester UK
    Beans
    13,573
    Distro
    Ubuntu

    Re: variables in .bashrc: how to using dir path

    To use variables use functions in your .bashrc

    eg

    Code:
    function blah () {
             blah blag -x -y -z; complicated commands; including \
             one "$1"; or more variables "$2"; blah blah
                     }
    In this form, it is more or less the same as an alias, blah will execute the stuff in between the curly brackets.

  4. #4
    Join Date
    Apr 2006
    Location
    Ubuntuland
    Beans
    2,124
    Distro
    Ubuntu 13.10 Saucy Salamander

    Lightbulb Re: variables in .bashrc: how to using dir path

    On further review, $1 etc. are not appropriate for use by an alias.

    aliases are a little different than functions, etc.

    Here is an example:
    $ alias tryme='echo 1=$1 2=$2'
    $ tryme 1 2
    1= 2= 1 2

    I would highly recommend the Advanced Bash Scripting Guide (I know that it has some issues, some people will mention these). Even the man page is very helpful.
    24 beers in a case, 24 hours in a day. Coincidence? I think not!

    Trusty Tahr 64 bit, AMD Phenom II 955 Quad Core 3.2GHz, GeForce 9600 GT
    16G PC2-6400 RAM, 128 GB SSD, Twin 1TB SATA 7200 RPM RAID0

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
  •