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 06-11-2010, 12:17 PM   #1
mattst
LQ Newbie
 
Registered: Apr 2010
Posts: 26

Rep: Reputation: 0
Quote char problem on command line.


I've a quote char problem on the command line which I'd like explained please.

Looking for a way to kill a process by name and not by process ID, I found this exact command on the web.

kill -9 `pgrep string`

Note the use of the `` chars and not single ' or double " quote chars.

The command above copied'n'pasted but substituting the process name for string worked fine, killing the process.

However using the quote chars which I have on my keyboard, ' and " do not work instead of ``.

[maya ~] kill -9 'pgrep nano'
-bash: kill: pgrep nano: arguments must be process or job IDs
[maya ~] kill -9 "pgrep nano"
-bash: kill: pgrep nano: arguments must be process or job IDs
[maya ~] kill -9 `pgrep nano`

The first 2 failed but the 3rd works fine.

Now I know that I can use pkill -9 nano instead, the purpose of this post is not to find how to do it but why the `` chars which are not on my keyboard work in the command and both ' and " do not?

Thanks.
 
Old 06-11-2010, 12:21 PM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Hi there,

The ``` chars are "backticks", not quotes. They cause the command(s) within them to be executed in a sub-shell, and the results of that command are then substituted into the original command.

Backticks are usually located on the top-left key on your keyboard, where the ~ tilde is. As a substitute, if you really do not have backticks available, is to use $() instead:

$(pgrep nano) instead of `pgrep nano`

See here for more on backticks and $(): http://mywiki.wooledge.org/BashFAQ/082

Sasha
 
Old 06-11-2010, 12:25 PM   #3
nuwen52
Member
 
Registered: Feb 2009
Distribution: Debian, CentOS 5, Gentoo, FreeBSD, Fedora, Mint, Slackware64
Posts: 208

Rep: Reputation: 46
Okay, as I understand quoting in shell (at least in bash):
`` = execute the command within the quotes (backticks) and return the output
'' = a string, with no translation for variables (literal string).
"" = a string, with translation for variables.

In the case of the last two:
Code:
#!/bin/bash
THIS="test"
echo "$THIS"
echo '$THIS'
shows:
Code:
test
$THIS

Last edited by nuwen52; 06-11-2010 at 12:27 PM.
 
Old 06-11-2010, 12:53 PM   #4
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 164Reputation: 164
Yeap...
$( ) is the new 'preferred' form of ` ` (both work, there are a lot of reasons for the change, which you can find by searching.)

Code:
#!/bin/bash 
VAR="This is text"
echo "$VAR"
echo '$VAR'
echo `echo $VAR | sed 's/text/sparta/'`
for i in $(seq 1 3); do echo "this is clone $i"; done
Code:
This is text
$VAR
This is sparta
this is clone 1
this is clone 2
this is clone 3
 
Old 06-11-2010, 01:20 PM   #5
mattst
LQ Newbie
 
Registered: Apr 2010
Posts: 26

Original Poster
Rep: Reputation: 0
Thank you all very much for your replies, now I understand.

I'll use the $() notation from now on as I have a reduced size keyboard and although the backtick chars are indeed on my keyboard after all (on the 1 key, thanks GrapefruiTgirl) I have to use a nasty key-combo to get them.

Thanks again all.
 
Old 06-11-2010, 01:22 PM   #6
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Cool, glad it all helped. If that's it, you can mark this thread "SOLVED" using the "Thread Tools" near the top of the page, if you haven't already.

Cheers!
Sasha
 
Old 06-11-2010, 01:31 PM   #7
mattst
LQ Newbie
 
Registered: Apr 2010
Posts: 26

Original Poster
Rep: Reputation: 0
Have now.
 
  


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
Programing Question: Reading file line by line.. then char by char in each line adriumroot Programming 8 05-30-2010 02:55 AM
sed : Convert double quote to singe quote pgb_710 Programming 6 01-21-2010 08:59 AM
when to quote or not to quote variable names - mktemp problem glinux Linux - Newbie 3 02-20-2009 05:37 PM
I think that is problem with convertin char to const char* shifter Programming 8 10-04-2008 07:00 AM
gvim - double quote char always replaced with two single quotes in special modes JazzItSelf Linux - Software 4 09-16-2008 12:26 PM


All times are GMT -5. The time now is 11:45 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