" in a Bash here-document
Hi,
I stumbled about an issue where quotation marks are either removed or output including the escape character: Code:
CMDOPT_F=1 Code:
line 1 Code:
CMDOPT_F=1 Code:
line 1 I succeeded by using a variable for the quotation mark: Code:
QUOTE=\" Code:
line 1 -- Reuti |
it seems to be this construct
Code:
pam${CMDOPT_F+ --get="${FILES}"} Code:
pam --get="$FILES" Code:
#!/bin/bash -e |
Quote:
Thx for looking into this. The construct ${parameter+word} is used here, as I want the --get option only in case CMDOPT_F was set. Otherwise nothing should be appended. Sorry for neglecting this prerequisite. -- Reuti |
in which case you are using the wrong construct this is the correct way to set a default value to a variable in bash
Code:
echo ${MYVAR:-"Default Val"} |
There are four variations for alternate values in variable expansion. From man bash:
Code:
${parameter:-word} You can nest quotes inside parameter substitutions, so I believe you want to use the version I supply below. As for heredocs, I have personally come to dislike them, for the most part. I find them hard to set up correctly and awkward to read. My preference is usually to use an array, with each index holding one line of text. Code:
CMDOPT_F=1 Code:
line 1 Code:
myscript+=( "pam${FILES:+" --get='$FILES'"}" ) |
[QUOTE=David the H.;6011913]There are four variations for alternate values in variable expansion. From man bash:
Code:
... Not seen these before, is it new? You learn something new every day :) |
Is there a reason you cannot switch to single quotes?
This worked for me: Code:
CMDOPT_F=1 |
What bash version?
I have seen such incorrect parsing in bash-3 that got corrected in bash-4. |
Quote:
-- Reuti |
Quote:
-- Reuti |
All times are GMT -5. The time now is 10:30 PM. |