LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-09-2013, 09:41 AM   #1
sam_sung
LQ Newbie
 
Registered: Oct 2012
Posts: 27

Rep: Reputation: Disabled
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
    mkdir -p "${STEAM_DATA_HOME}/applications"
fi
sed "s!/usr/bin/steam!${STEAM_DIR}/steam_on_debian.sh!" tree/usr/share/applications/steam.desktop > "${STEAM_DATA_HOME}/applications/steam.desktop"
cp -R tree/usr/share/icons "${STEAM_DATA_HOME}"


### Start: Code Block 3
echo "Adding Steam to PATH"
MAGIC_LINE="[[ -f \"${STEAM_DIR}/setup_debian_environment.sh\" ]] && source \"${STEAM_DIR}/setup_debian_environment.sh\""

cat > "${STEAM_DIR}/setup_debian_environment.sh" <<EOF
if ! which steam > /dev/null 2>&1; then
    PATH="${STEAM_DIR}/debian_bin:${PATH}"
    export PATH
fi
 
Old 05-09-2013, 12:02 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
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
I failed to see the exclamation mark in the above line of code?
 
Old 05-09-2013, 12:20 PM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by sam_sung View Post
sed "s!/usr/bin/steam!${STEAM_DIR}/steam_on_debian.sh!" tree/usr/share/applications/steam.desktop > "${STEAM_DATA_HOME}/applications/steam.desktop"
Little tricky, but see here as well.
A ! character is used in sed to invert the restriction.

Last edited by shivaa; 05-09-2013 at 12:21 PM.
 
Old 05-09-2013, 12:20 PM   #4
sam_sung
LQ Newbie
 
Registered: Oct 2012
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
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
I failed to see the exclamation mark in the above line of code?

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.
 
Old 05-09-2013, 12:25 PM   #5
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 979
Blog Entries: 2

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by sam_sung View Post
i meant was the ! in IF statement after that.

You can use a conditional block to execute only if some test is met:
Code:
if true
then
  echo The man from Finland says YES  
fi
and you can test for the opposite condition by putting ! between "if" and "true".
 
Old 05-09-2013, 12:42 PM   #6
sam_sung
LQ Newbie
 
Registered: Oct 2012
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by linosaurusroot View Post
You can use a conditional block to execute only if some test is met:
Code:
if true
then
  echo The man from Finland says YES  
fi
and you can test for the opposite condition by putting ! between "if" and "true".
sorry again, i meant the following code

Code:
if ! which steam > /dev/null 2>&1; then
    PATH="${STEAM_DIR}/debian_bin:${PATH}"
    export PATH
fi
 
Old 05-09-2013, 12:50 PM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
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.
 
Old 05-10-2013, 10:47 AM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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
This will delete all lines except for the section starting with line 10 and ending with the next line that contains "foo".

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
sed 's!foo!bar!' infile
sed 's_foo_bar_' infile
sed 's@foo@bar@' infile
The address range regex field can be changed too, but you have to precede the delimiter with a backslash.

Code:
sed '10,\!foo!!d infile
Now, in the shell...

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 $?
2
! ls non-existing-file ; echo $?
0
So naturally, when used in a loop or if test, it means that the sub-command runs if the command fails.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
atq command output exclamation mark Effendi Linux - Newbie 2 06-28-2012 01:31 AM
[SOLVED] sed help to run sed command against multiple different file names bkone Programming 2 04-16-2012 01:27 PM
[SOLVED] sed exclamation Moshanator Linux - General 4 08-25-2010 10:08 AM
[SOLVED] Can't Type an Exclamation Mark wingman358 Ubuntu 2 07-06-2010 04:30 PM
Server Indicate Exclamation mark (!) Prabuddha Linux - Hardware 1 06-15-2009 08:43 AM


All times are GMT -5. The time now is 06:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration