Reputation: 9437
I am trying to generate a file given a template with this code in test.sh
:
#!/bin/sh
#define parameters which are passed in.
ID=$1
DIRECTORY=$2
#define the template.
cat <<EOF
./pgap.py -D singularity -r -o $DIRECTORY/$ID $DIRECTORY/$ID'_input.yaml'
I used '
in the last line to avoid the text trailing the $ID
variable to be mixed with it. But when running the code prints both '
.
In other words, when I run:
bash test.sh id dir
I get
./pgap.py -D singularity -r -o dir/id dir/id'_input.yaml'
, but I'd like to get:
./pgap.py -D singularity -r -o dir/id dir/id_input.yaml
Upvotes: 1
Views: 108
Reputation: 88583
Replace
$DIRECTORY/$ID'_input.yaml'
with
$DIRECTORY/${ID}_input.yaml
Upvotes: 3
Reputation: 41
You can achieve what you're trying to do with the single quotes by enclosing the variable name in curly braces, i.e. $DIRECTORY/${ID}_input.yaml
Upvotes: 1