Why am I unable to complete my bash script with this #
-comment?
My script doesn't execute passed the commented line.
Does it have to do with using \
backlashes in the preceding line?
"$PSQL_HOME"/psql -h $HOST_NM \
-p $PORT \
-U postgres \
-v v1=$1 \
-v v2=$_load \
# -f Test.sql
-f Test2.sql
You can't do that. \
joins the current line to the next one, so what bash sees is:
"$PSQL_HOME"/psql ... -v v1=$1 -v v2=$_load # -f Test.sql
-f Test2.sql
You can move the comment to the last line in this particular case:
"$PSQL_HOME"/psql -h $HOST_NM \
-p $PORT \
-U postgres \
-v v1=$1 \
-v v2=$_load \
-f Test2.sql
# -f Test.sql
Technically, the first six lines of your script are a single line for the shell. A comment stop the interpretation of the current line until its end so there is no way to have the line resuming after the #
comment.
Should you want to keep the order of options for some reason, you might use that syntax:
"$PSQL_HOME"/psql -h $HOST_NM \
-p $PORT \
-U postgres \
-v v1=$1 \
-v v2=$_load \
$(: -f Test.sql) \
-f Test2.sql
The $( ... )
is replacing a portion of a command by the execution of what is inside the parenthesis. The :
is kind of a null command, somewhat similar to a #
but unlike it, it doesn't end the current line so the outer command line can resume after it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With