I have the following script:
#!/bin/bash
cat $1.txt | awk "{cmd=\"pwgen 10 1\"; cmd | getline pass; print substr($0, 1, length($0) -1) \">> ~/dresses/whole-dresses-shape/$1-\" pass \".jpg\"; close(cmd);}" | bash
Inside the awk "{}"
command, the $0
variable is supposed to refer to the line being currently read from cat $1.txt
. However, when used from inside a script file, $0
takes the value of the name of the file being executed.
How can I make sure that the substr()
function takes the output from cat
in this example?
Desired workflow:
- user enters
./myscript.sh hello
$1
takeshello
value- each line read from
cat
is assigned to what is currently displayed as$0
$1
which is not right anymore. It becomes a literal $1, instead of recalling the variable. Any way to escape this? – Jivan Feb 26 '20 at 16:57