0

Basically, I want to send a variable as $1 in another script without the value it has saved.

#!/bin/bash

echo -e "#!/bin/bash\ncp ~/src/$1" > ~/asset/newfile.sh

So, that in the file newfile.sh it is written:

#!/bin/bash

cp ~/src/$1
Cyrus
  • 77,979
  • 13
  • 71
  • 125
TheMathAI
  • 87
  • 5

1 Answers1

0

You can escape the dollar sign with a backslash:

echo -e "#!/bin/bash\ncp ~/src/\$1"

Or, switch to single quotes:

echo -e '#!/bin/bash\ncp ~/src/$1'
choroba
  • 216,930
  • 22
  • 195
  • 267
  • Boo, hiss re: `echo -e` (vs showcasing `printf`, and thus demonstrating code that would reliably work across all POSIX shells) – Charles Duffy Oct 02 '21 at 22:43