cp command not working with alias


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers cp command not working with alias
# 1  
Old 10-03-2011
cp command not working with alias

Hi Friends,

I have added some aliases in .bash_profile file under the root folder. Its works fine and very useful, but does not go well with cp command.
Code:
alias deploy="cd  /usr/local/tomcat/webapp"
alias artifacts="cd  /usr/local/artifacts"

but when i try to cp from artifacts folder using like the below
cp app.war deploy
the above command does not work and instead it copies the app.war to a new file named deploy inside the same folder. How to make the above command to copy the war file to deploy folder.

Last edited by Scott; 10-03-2011 at 02:30 PM.. Reason: Added code tags
# 2  
Old 10-03-2011
Hi.

From the "BASH" man page:

Code:
ALIASES
       Aliases allow a string to be substituted for a word when it is used  as
       the  first  word  of  a  simple command.

If you want to use "deploy" as an argument to "cp" (in this case as the target directory(Smilie), then you should use a variable (say, "DEPLOY")

Code:
$ DEPLOY=/usr/local/tomcat/webapp

$ cp app.war "$DEPLOY"

This User Gave Thanks to Scott For This Post:
# 3  
Old 10-03-2011
You could also make a function:

Code:
function deploy
{
        cp -i "$@" /usr/local/tomcat/webapp/
}

Code:
deploy file1 file2 ...

-i for safety, should ask if you really want to overwrite files.

Last edited by Corona688; 10-03-2011 at 05:03 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Lost with this alias why it is not working

Hi, I have the following aliases: $: alias | grep "^du=" du='du -s * 2>/dev/null | awk '\''{ printf "%4.2f-KB ==> %s \n", $1/1024 , $2 }'\'' | sort -rn' $: alias | grep "^dutop10=" dutop10='du -s * 2>/dev/null | awk '\''{ printf "%4.2f-KB ==> %s \n", $1/1024 , $2 }'\'' | sort -rn | head... (2 Replies)
Discussion started by: newbie_01
2 Replies

2. Shell Programming and Scripting

Alias not working

I have several shell scripts which contain the nawk command. Here is what i m doing assign the correct value to nawk as nawk is not found on a new systems. Here is what i did. more test.sh ] && alias nawk=/usr/bin/gawk ] && alias nawk=/usr/bin/nawk ] && alias nawk=/usr/bin/awk... (7 Replies)
Discussion started by: mohtashims
7 Replies

3. Solaris

Alias is not working under Bourne Shell

Hi, Please assist me why HC alias is not working under this shell? root@singapore # grep HC /.profile alias HC='cd /var/tmp/HC/2015/`date +%B`' root@singapore # . /.profile Sourcing //.profile-EIS..... root@singapore # echo $HC root@singapore # HC HC: not found root@singapore # echo... (18 Replies)
Discussion started by: tprabhu1983
18 Replies

4. Solaris

Alias not working

Hi, I'm on Solaris (SunOS wsp2cm01 5.10 Generic_150400-10 sun4v sparc SUNW,Sun-Fire-T200). Trying to set up an alias like below - alias grep="/usr/xpg4/bin/grep"but when I call grep in my command it ignores my alias & uses /usr/bin/grep instead. The problem with /usr/bin/grep is that it doesn't... (24 Replies)
Discussion started by: nexional
24 Replies

5. Red Hat

[SOLVED] How the alias is working?

Iam facing some strange issue with alias. I have an alias file in which i have created lot of aliases as given below. export BUILD_HOME=/apps/psr/build export DB_HOME=/apps/psr/database export LOGS_HOME=/apps/psr/logs export BUILD_TEST=/apps/psr/build_dev/build_test export... (0 Replies)
Discussion started by: Vikram_Tanwar12
0 Replies

6. Solaris

Simple question: alias not working for root

OS = Solaris 8 Issue: alias not working for root, but working for regular users # grep root /etc/passwd root:x:0:1:Super-User:/:/sbin/sh # alias dir=ls # dir dir: not found # alias dir="ls -l" # dir dir: not found # alias dir='ls -l' # dir dir: not found # alias... (2 Replies)
Discussion started by: aixlover
2 Replies

7. Solaris

Alias not working

Hello, I am trying to set an alias in my .kshrc or .profile and when I do it is not setting. If I do it manually it works fine. Is there another file I should put this in? Here is the alias I am using. alias ll='ls -ltr' I am using solaris 9. When I type alias it does not show these... (5 Replies)
Discussion started by: dkranes
5 Replies

8. UNIX for Dummies Questions & Answers

alias command not working after re-login

i create some alias in .cshrc file then i run source .cshrc to refresh it, the alias command work fine but when i relogin again, the alias command is not working... i need to re-run the source .cshrc command so that the alias only workable. any idea on it? (7 Replies)
Discussion started by: lsy
7 Replies

9. UNIX for Dummies Questions & Answers

alias not working in scripts

Hi All, PF below details, > cat run.sh #!/usr/bin/ksh alias ll="ls -l" > ./run.sh > ll ksh: ll: not found. Pls help on this? Thanks in Advance, Naga :cool: (2 Replies)
Discussion started by: Nagapandi
2 Replies

10. UNIX for Advanced & Expert Users

Alias a command

Hi 'm executing a java program from my shell script on solaris 9 as $JAVA_HOME\bin\java -ms32m -mx128m -classpath $CLASSPATH com.abc.fwk,abcServer.abcfwkServer $1 & where $1 is port number when i do ps -ef, it shows whole command , i want to give this some alias name as abcProcess, so... (2 Replies)
Discussion started by: b_garima
2 Replies
Login or Register to Ask a Question