sed command with exclamation mark
hey.. can anyone explain what this sed command doing in this script? i can't understand the exclamation marks in sed command. and another exclamation mark in the cat command line.
i had my brain faded understanding it. i didn't get any idea from anywhere. neither in man pages nor on the internet. please shed some light Code:
if [ ! -d "${STEAM_DATA_HOME}/applications" ]; then |
Sed allows you to alter the delimiters used in case you have conflicting data being searched, ie. if you used the defaults (s///) you would need to escape all slashes in the string being
searched for and the string you are replacing. (see here for more info) As for cat: Code:
cat > "${STEAM_DIR}/setup_debian_environment.sh" <<EOF |
Quote:
A ! character is used in sed to invert the restriction. |
Quote:
thanx for the reply sir. i did not understand it fully as i am new to linux environment. sir, could you please provide any more examples please. sorry about the ambiguity of cat exclamation mark, what i meant was the ! in IF statement after that. |
Quote:
You can use a conditional block to execute only if some test is met: Code:
if true |
Quote:
Code:
if ! which steam > /dev/null 2>&1; then |
linosaurusroot's post was an example but means the same in the code you are looking at. which is a command and the ! will negate its exit status based on the test of finding steam.
As for sed, did you read the link I gave you, it does provide other examples. |
We've got lots of things going on here. Let's try to break them down.
Let's start with sed. 1) When used with an address or address range, it means "not". Code:
sed '10,/foo/!d infile 2) It can be used as a delimiter in the 's' substitution, as mentioned. But any simple ascii character can be used, not just '!'. The command will simply use the first character after 's' as the delimiter. These are all the same: Code:
sed 's/foo/bar/' infile Code:
sed '10,\!foo!!d infile Among other uses, adding a '!' in front of a command reverses the exit code. A successful 0 exit code will become 1, and a non-zero exit code becomes 0. Code:
ls non-existing-file ; echo $? |
All times are GMT -5. The time now is 08:46 AM. |