Monday, 7 May 2018

bash - alias for cp with arguments




How do I modify bashrc to include a readme file with the pwd to original source every time I use cp or mv?



It should be something like this:




alias cp="pwd $1 > readme & cp $1 $2"


or



alias cp="pwd $1 > readme | cp $1 $2"


But instead of the path of the source, it gives me the path of the directory I am in.



Answer



You can't have aliases with arguments. Since you probably don't have $1 defined, pwd $1 just expands to pwd.



Also, pwd doesn't actualy take any positional arguments. If you want the source to appear in readme, use echo.



Create a function



cp() {
echo $1 > readme
/bin/cp $1 $2

}





Also,




  • & does not mean AND – it sends processing to background

  • | does not mean OR – it pipes output of left side to input of right side



No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...