bash: !": event not found in Ubuntu 13.04 [duplicate] - linux

This question already has answers here:
echo "#!" fails -- "event not found"
(5 answers)
Closed 7 years ago.
I am facing the following error
bash: !": event not found
while i have write the following command
echo "HI" test.txt
in terminal,
whats the problem?

You are probably typing it as:
echo "HI!" >> test.txt
! is a special character in bash (Linux) and needs to be escaped like so:
echo "HI\!" >> test.txt
I think this question is answered very well in this link: https://serverfault.com/questions/208265/what-is-bash-event-not-found?newreg=2077048244ee45dbb6f7d1925d71458f
Hope this helps.

You have a syntax error in your command, You need to add the '>>' between your text and your name file and also try removing the quotes:
echo HI >> test.txt

Related

Bash how to store in a variable the result of a linux command? [duplicate]

This question already has answers here:
How do I set a variable to the output of a command in Bash?
(15 answers)
Why does a space in a variable assignment give an error in Bash? [duplicate]
(3 answers)
Closed 2 years ago.
I'm trying to store in a variable the temperature of the computer. I tried this but it doesn't work:
#!/bin/bash
temp = cat "/sys/class/thermal/thermal_zone0/temp"
echo "$temp"
i tried this too:
#!/bin/bash
temp = $(cat "/sys/class/thermal/thermal_zone0/temp")
echo "$temp"
but nothing works, it always says
./temp.sh: line 2: temp: command not found
Spaces are crucial! This works fine:
# NO space around `=`
temp=$(cat "/sys/class/thermal/thermal_zone0/temp")
echo "$temp"

How to echo this entire code to .bashrc without leaving out characters/strings? [duplicate]

This question already has answers here:
How do I properly quote this bash pipeline for watch?
(2 answers)
Closed 3 years ago.
How can I echo this entire piece of code to .bashrc without leaving out a single character?
# automatic logging of terminal input/output
test "$(ps -ocommand= -p $PPID | awk '{print $1}')" == 'script' || (script -f -q /home/user/.logs/terminal/manjaro/$(date +"%Y-%m- %d_%H:%M:%S")_terminal.log)
When I attempt to enter the following into terminal:
echo "the above code" >> ~/.bashrc
I get the following appended to .bashrc which is nothing like "the above code", its short about 45 or so characters.
# automatic logging of terminal input/output
test script == 'script' || (script -f -q /home/user/.logs/terminal/manjaro/2019-05- 08_09:09:19_terminal.log)
As you can see, it's leaving out A LOT of the original code. I understand this has a lot to do with the number of different quotations and placement, but without altering my code much, or at least to the point where it can still function as its intended, how can I go about getting this to echo to the file properly?
Thank you for every nanosecond of your time.
Wrap your echo'd string with single quotes ' instead of double "

Bash echo weird behavior [duplicate]

This question already has answers here:
Variables overwriting text problem with "echo" in Bash
(2 answers)
Closed 4 years ago.
I wrote a script to change .CSV to json.
#!/bin/bash
exec 0< example.csv
while IFS=, read name element input decrease
do
echo "${element}decrease: ${decrease}test"
done
the example.csv I paste here
name1,A,11,12
name2,B,13,14
But the output is really weird...
testrease: 12
testrease: 14
As u can see, The test rewrite Adecrease and Bdecrease, makes them to testrease.
I can't believe it!! So I tried with out exec 0< example.csv, type them in stdin, this time I got what I want
name1,A,11,12
Adecrease: 12test
So I guess maybe there are some characters in example.csv I can't see which makes this problem. I use cat -v example.csv
name1,A,11,12^M
name2,B,13,14^M
Nothing strange and I stuck here.
I am very new to shell script, so if anyone can give me some suggestions I will be really thrilled!!
Thank u, #chepner! tag wiki saves me another hour on this stupid question.
And here is the solution from wiki:
Check whether your script or data has DOS style end-of-line characters.
Use cat -v yourfile or echo "$yourvariable" | cat -v.
DOS carriage returns will show up as ^M after each line.
If you find them, delete them using dos2unix (a.k.a. fromdos) or tr -d '\r'.

Linux bash line override itself [duplicate]

This question already has answers here:
Why is this bash prompt acting strangely/disappearing, and how do I fix it (OS X)?
(3 answers)
Closed 7 years ago.
I made my own .bashrc (part of code below) and in test by pressed arrows up/down: i found that
history of commands override static text of line or leaves last command and print new over it. How to fix that?
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
RESTORE=$(echo -en '\033[0m')
RKNAME=$(echo -en '\033[38;5;106m')
RKPATH=$(echo -en '\033[38;5;229m')
RKBRANCH=$(echo -en '\033[38;5;44m')
RKGIT=$(echo -en '\033[38;5;250m')
pathToFolder=$PWD;
if [[ $pathToFolder =~ .*_GitRepo.* ]]
then
PS1='${RKNAME}\u#\h${RESTORE} ${RKGIT}Git ${RKPATH}\W\ ${RKBRANCH}$(parse_git_branch) \n ${RKGIT}-- $ ${RESTORE} '
fi
Resolve my problem is:
However, I had the same line-wrapping problem you did. The fix was to insert [ and ] around the ANSI escapes so that the shell knows not to include them in the line wrapping calculation.
Thanks, #Gillies for link Why is this bash prompt acting strangely/disappearing, and how do I fix it (OS X)?

How to store and echo multiple lines elegantly in bash? [duplicate]

This question already has answers here:
Capturing multiple line output into a Bash variable
(7 answers)
Closed 5 years ago.
I'm trying to capture a block of text into a variable, with newlines maintained, then echo it.
However, the newlines don't seemed to be maintained when I am either capturing the text or displaying it.
Any ideas regarding how I can accomplish this?
Example:
#!/bin/bash
read -d '' my_var <<"BLOCK"
this
is
a
test
BLOCK
echo $my_var
Output:
this is a test
Desired output:
this
is
a
test
You need to add " quotes around your variable.
echo "$my_var"

Resources