-2

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.

pacholik
  • 8,607
  • 9
  • 43
  • 55
thatgeeman
  • 13
  • 7

1 Answers1

2

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
pacholik
  • 8,607
  • 9
  • 43
  • 55
  • this is okay, I carried out `unalias cp` and tried your method, but does not change the result. It's still the `pwd` to current directory. – thatgeeman Oct 17 '17 at 14:53
  • @thatgeeman Well that's what `pwd` does. Replace it with `echo` if you want the source in *readme*. – pacholik Oct 17 '17 at 15:14