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
  • 84,225
  • 14
  • 89
  • 153
TheMathAI
  • 97
  • 6

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
  • 231,213
  • 25
  • 204
  • 289
  • 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