This question already has answers here:
echo "#!" fails -- "event not found"
(5 answers)
Closed 5 years ago.
when i am trying to remove consecutive duplicate lines with
awk "!x[$0]++" file
its reporting x[: Event not found.
even the same case with
sed -i -e "$!N; /^\(.*\)\n\1$/!P;D" file as well reporting
N: Event not found.
i tried with single quotes too, it didn't help
Any idea to fix those
You're invoking the shell's history substitution. Surround the exclamation point with single quotes.
Related
This question already has answers here:
When to wrap quotes around a shell variable?
(5 answers)
Why does shell ignore quoting characters in arguments passed to it through variables? [duplicate]
(3 answers)
Closed 7 months ago.
To recreate this you will need to create a file named "l l.tex" in your home directory. Then make a an executable script with the following code
alacritty -e vim l\ l.tex
This opens the file, as I desired. Now create the following script
var="/home/l\ l.tex"
dar=$(echo $var | sed 's/\/home\//\#/g')
bar=$(echo $dar | sed 's/#//g')
alacritty -e vim $bar
This script, however, makes two new documents. However, they should be the same. I think there is an issue with how $bar is read. I am novice at this, but I reckon that this has to do with how strings are stored.
Can someone help me fix the second code so that I can use a variable?
This question already has answers here:
bash script execute command with double quotes, single quotes and spaces
(2 answers)
How to execute a bash command stored as a string with quotes and asterisk [duplicate]
(5 answers)
Closed 1 year ago.
I have a script to output git commits with specific jira ticket and within a date and time range, however i keep hitting an error, my codes are below:
SINCE="2021-02-26 17:59:58"
BEFORE="2021-03-05 17:59:58"
CMD="git log -p -m -name-status --since=\"${SINCE}\" --before=\"${BEFORE}\" --grep=${TICKET}
${CMD} >> out.txt
Error:
Fatal: Invalid object name '17'
I tried enclosing the cmd with "" "${CMD}" also getting same error.
Anyone know what is wrong with it?
This question already has answers here:
Brace expansion with variable? [duplicate]
(6 answers)
how to use variables with brace expansion [duplicate]
(2 answers)
Closed 2 years ago.
I have the following in my bash file:
echo "Spawning $1 processes"
for i in {1..$1}
do
(go run loadgen.go $2 &)
echo "done."
done
However, I can only seem to get my go file to execute once. I know that they're started in the background, but each of my go files should append to the same log file (I can reproduce this by running my bash script multiple times). Am I doing something wrong to get this to iterate multiple times?
This question already has answers here:
echo "#!" fails -- "event not found"
(5 answers)
! in a string makes it unusable in a command line - error message "event not found" [duplicate]
(1 answer)
-bash: !/usr/bin/env: event not found [duplicate]
(1 answer)
Closed 3 years ago.
I have a basic question about Shell interpretation
When i make something like :
echo "#!/bin/bash"
-bash: !/bin/bash: event not found
What does the shell really pass to the echo command.
If i understand well, the double quote make the shell doesnt do globbing.
! is used for history expansion, not for globbing.
From the bash documentation:
Enclosing characters in double quotes preserves the literal value of
all characters within the quotes, with the exception of $, `, \, and,
when history expansion is enabled, !.
This question already has answers here:
Difference between single and double quotes in Bash
(7 answers)
Closed 7 years ago.
I have a script part where I am checking if the file exist . I dont find where is my mistake because it jumps to else( file exists) and starts downloading that file. Part of code:
...
if [ -f '$ins.img' ];
then
echo '$ins.img already exists'
else
wget http://$2/$ins/$ins.img
fi
...
It's because you're using single quotes in your if. Variables are not filled in inside single quotes, so it will check for a file literally named $ins.img, which obviously doesn't exist.
The solution is easy, use double quotes.