Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I "aliased" a shell command in this way:

alias "myapplication"="/home/manuel/myapp/bin/startapp.sh"

Now i'd like to pass to it a relative file-path where i am when i execute the aliased command, like this:

manuel@gemini:~/Desktop/myfolder$ myapplication myfile.xml

but the aliased application get only the filename myfile.xml

Should i add something in the alias lines?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

Aliases do not do arguments. You need a shell function for this.

function myapplication() { /home/manuel/myapp/bin/startapp.sh "$@" ;}

Now you can call myapplication() with:

myapplication myfile.xml
share|improve this answer
    
Thanks for your help Rinzwind, but it doesn't work :(. I added the function you wrote in .bashrc, now shell has the command "myapplication", but it still load "myfile.xml", not "path/where/i/am/myfile.xml". Why? –  Manuel Bitto May 3 '11 at 12:19
    
ah I misunderstood your question then, sorry :P htorque's answer might be better (but we need the source of your script to know that for sure ;) –  Rinzwind May 3 '11 at 12:36

Your problem lies within your application. If you want to get the absolute path from a relative one, try this one in your application/script:

abs_path=$(readlink -m "$1")
share|improve this answer
    
Ok, i substitute $@ with $(readlink -m "$1") in the function that calls .sh file and now it works. Both of you are right. Thanks –  Manuel Bitto May 3 '11 at 12:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.