How to echo ![](../images/a.png) in bash? [duplicate] - bash

This question already has answers here:
echo "#!" fails -- "event not found"
(5 answers)
How to escape history expansion exclamation mark ! inside a double quoted string?
(4 answers)
Closed 2 years ago.
I have tried so many variations to echo the following string:
![](../images/a.png)
my attempts
b="a.pdf"
$ echo -n "![](../images/""${b%.*}.png")
-bash: ![]: event not found
$ echo -n "\![](../images/""${b%.*}.png"\)
\![](../images/a.png)
How to get:
![](../images/a.png)

Related

Save text block to file with bash [duplicate]

This question already has answers here:
How to cat <<EOF >> a file containing code?
(5 answers)
Using variables inside a bash heredoc
(3 answers)
Closed 16 days ago.
Below code try to save a text block to file with bash but report error:
#!/bin/sh
cat > FILE.txt <<EOF
x=1024
x=$(($x/1024))
echo $x
EOF
Error message:
$ ./a.sh
./a.sh: 3: ./a.sh: arithmetic expression: expecting primary: "/1024"
What's proper way to fix such error?

How to extract value from a string in shell script? [duplicate]

This question already has answers here:
Extract substring in Bash
(26 answers)
Closed 8 months ago.
I have this environment variable
echo $DT_CUSTOM_PROP
returns
APPCODE=IK22 ENVIRONMENT=DEV APPLICATION=xxxxx-xxxxx-xxxxx-xxxxx ANOTHERKEY=ANOTHERVALUE
How can I get APPLICATION from it?
So that if I do echo $APPLICATION I get xxxxx-xxxxx-xxxxx-xxxxx
Given:
DT_CUSTOM_PROP='APPCODE=IK22 ENVIRONMENT=DEV APPLICATION=xxxxx-xxxxx-xxxxx-xxxxx ANOTHERKEY=ANOTHERVALUE'
You can do it with parameter expansion in a 2-step process:
tmp=${DT_CUSTOM_PROP#*APPLICATION=}
application=${tmp%% *} # ==> xxxxx-xxxxx-xxxxx-xxxxx
Or with bash regex matching
if [[ $DT_CUSTOM_PROP =~ "APPLICATION="([^[:blank:]]+) ]]; then
application=${BASH_REMATCH[1]}
else
application="not found"
fi

bash loop problem - output not as expected (returned command) [duplicate]

This question already has answers here:
Brace expansion with variable? [duplicate]
(6 answers)
Closed 8 months ago.
I have a script.sh
#!/bin/bash
for i in {1..$1}
do
echo $i
done
someone could explain me why if I try
./script.sh 10 my output is {1..10}?
expected
1
2
...
10
You're echoing the parameter that you're passing in instead of printing out the loop iteration. Try:
echo $i

Shell gives error "[: too many arguments" when using while loop [duplicate]

This question already has answers here:
How can I compare a string to multiple correct values in Bash?
(5 answers)
Why does non-equality check of one variable against many values always return true?
(3 answers)
Closed 1 year ago.
I am very new to shell scripting, and i have had this error. I am using a while loop that goes a bit like this:
while [ "$variable" =! "hello" -o "$variable" =! "hi" ]
do
echo "variable isn't hi or hello"
done
but shell then gives the error [: too many arguments

bash variable expansion in if statement [duplicate]

This question already has answers here:
Tilde expansion in quotes
(3 answers)
Closed 7 years ago.
Checking for the existence of a directory which should resolve to ~/code/devtools/deploy-mix.
This if statement doesn't pass -- though I can cd ~/code/devtools/deploy-mix. Plz help with bash syntax :)
GIT_DIR="$HOME/code"
if [ -d "${GIT_DIR}/devtools/deploy-mix" ]; then
echo "found $GIT_DIR/devtools/deploy-mix"
fi
output:
sh -x script
'[' -d '$HOME/code/devtools/deploy-mix' ']'
I'd love to give out some internet karma for this one and I'm ok if you decide to call me a noob (sometimes the coding angle doesn't sit on your shoulder).
Replace ~ by $HOME or remove quotes.
Examples:
GIT_DIR="$HOME/code"
GIT_DIR=~/'code'

Resources