To quote or not | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

To quote or not

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-16-2013
g.j.huebschman g.j.huebschman is offline
Registered User
 
Join Date: Aug 2013
Last Activity: 20 August 2013, 3:42 PM EDT
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
To quote or not

My question is, "Do I not understand, or is my information out of date?"
I am trying to just be a student, rtfm'ing. I am working on my work systems. Is it simply that the book was printed in 2002 and a lot has changed since then, or did I miss something?

Working in Korn Shell.
I have been reading O'Reilly "Learning the Korn Shell." (Which deals with ksh93)
We have Version M-11/16/88f, not 93.

I was reading about quoting, and the book cited an example using the 'find' command. It states that I need to quote wildcards used in the find command. It also says I need to use "-print" to see the results.

I use the find command a lot. I have neither been quoting/escaping, nor using -print, but I get what I am looking for:

Code:
root@s0ms3rv3r:/ >find / -name *dsmerr*
/etc/dsmerror.log
/home/s0m3uz3r/.ssh/dsmerror.log
/home/s0m3uz3r/dsmerror.log
/home/s0m3uz3r/tsm/scripts/dsmerror.log
/sys/logs/tsm/dsmerror.log
/usr/local/adm/clscripts/dsmerror.log
/usr/local/adm/hacmp/bak/dsmerror.log
/usr/local/adm/hacmp/dsmerror.log
/usr/local/adm/scripts/archive/dsmerror.log
/usr/local/adm/scripts/dsmerror.log
/usr/tivoli/tsm/client/ba/bin/dsmerror.log
/usr/tivoli/tsm/server/bin/dsmerror.log
root@s0ms3rv3r:/ >set -o emacs
root@s0ms3rv3r:/ >Version M-11/16/88f
root@s0ms3rv3r:/ >find / -name '*dsmerr*'
/etc/dsmerror.log
/home/s0m3uz3r/.ssh/dsmerror.log
/home/s0m3uz3r/dsmerror.log
/home/s0m3uz3r/tsm/scripts/dsmerror.log
/sys/logs/tsm/dsmerror.log
/usr/local/adm/clscripts/dsmerror.log
/usr/local/adm/hacmp/bak/dsmerror.log
/usr/local/adm/hacmp/dsmerror.log
/usr/local/adm/scripts/archive/dsmerror.log
/usr/local/adm/scripts/dsmerror.log
/usr/tivoli/tsm/client/ba/bin/dsmerror.log
/usr/tivoli/tsm/server/bin/dsmerror.log
root@s0ms3rv3r:/ >
 
 
root@4nothrs3rv3r:/ >ls -ltr $(find / -name *dsmerr*)
-rwxrwx--- 1 root system 1450 Apr 28 2003 /usr/local/adm/clscripts/dsmerror.log
-rw-r----- 1 root system 1068 Jan 25 2007 /usr/local/adm/scripts/archive/dsmerror.log
-rw-r--r-- 1 root system 161 Apr 22 2010 /usr/lpp/tivoli.tsm.client.hsm.jfs2/dsmerror.log
-rw------- 1 root system 24112 Aug 14 13:17 /sys/logs/tsm/dsmerror.log
-rw-r--r-- 1 oracle dba 578 Aug 14 13:34 /sys/logs/tsm/orasched-dsmerr.log
root@4nothrs3rv3r:/ >ls -ltr $(find / -name '*dsmerr*')
-rwxrwx--- 1 root system 1450 Apr 28 2003 /usr/local/adm/clscripts/dsmerror.log
-rw-r----- 1 root system 1068 Jan 25 2007 /usr/local/adm/scripts/archive/dsmerror.log
-rw-r--r-- 1 root system 161 Apr 22 2010 /usr/lpp/tivoli.tsm.client.hsm.jfs2/dsmerror.log
-rw------- 1 root system 24112 Aug 14 13:17 /sys/logs/tsm/dsmerror.log
-rw-r--r-- 1 oracle dba 578 Aug 14 13:34 /sys/logs/tsm/orasched-dsmerr.log

I am not being deliberately thick. I am inclined to assume, "old book, old shell, it works how it works, move on..."
But, I have hamstrung myself in the past by carrying around half-misunderstood concepts. Quoting and regex are things that are fuzzy to me, and I want to get them straight.

Last edited by Scott; 08-16-2013 at 10:56 AM.. Reason: Please use code tags
Sponsored Links
    #2  
Old 08-16-2013
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 25 October 2014, 2:06 AM EDT
Location: Amsterdam
Posts: 9,549
Thanks: 285
Thanked 2,426 Times in 2,174 Posts
If you leave a pattern unquoted it will work too, unless there happens to be one or more files in the current directory that match that pattern (the shell will then expand the pattern first), which can lead to surprising results, so it is a good habit to quote those patterns..

Last edited by Scrutinizer; 08-16-2013 at 11:09 AM..
Sponsored Links
    #3  
Old 08-16-2013
g.j.huebschman g.j.huebschman is offline
Registered User
 
Join Date: Aug 2013
Last Activity: 20 August 2013, 3:42 PM EDT
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Thanks!

...and sorry about not using the code tag in my post.

---------- Post updated at 11:18 AM ---------- Previous update was at 11:10 AM ----------

Quote:
Originally Posted by Scrutinizer View Post
If you leave a pattern unquoted it will work too, unless there happens to be one or more files in the current directory that match that pattern (the shell will then expand the pattern first), which can lead to surprising results, so it is a good habit to quote those patterns..
My takeaway is to use quotes.
I can also see that I don't understand the difference between the shell expanding the wildcards and the command expanding the wildcards. I'll go back and read again. I'll try some test file names to see how things work.

(Now I see that there is a "Thanks" button.)
    #4  
Old 08-16-2013
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 25 October 2014, 2:06 AM EDT
Location: Amsterdam
Posts: 9,549
Thanks: 285
Thanked 2,426 Times in 2,174 Posts
It means that the shell will expand the pattern and pass the resulting file names as a parameter to find (so find will never "see" a pattern, just the expansion result), which will lead to a syntax error if the result is more than one file and and to the wrong result if it just one file:

A short illustration would be:

Code:
$ ls
$ mkdir dir1
$ touch fileA fileB dir1/fileC dir1/fileD
$ find . -name 'file*'              # the shell does not expand patterns within quotes, so the shell removes the quotes and file* gets passed to find
./dir1/fileC
./dir1/fileD
./fileA
./fileB
$ find . -name file*                # pattern get expanded to fileA fileB
find: fileB: unknown primary or operator
$ rm fileB
$ find . -name file*                # pattern get expanded to fileA
./fileA
$ rm fileA
$ find . -name file*                # pattern does not get expanded, since no files with that pattern are present in the current directory.
./dir1/fileC
./dir1/fileD


Last edited by Scrutinizer; 08-16-2013 at 11:45 AM..
Sponsored Links
    #5  
Old 08-16-2013
g.j.huebschman g.j.huebschman is offline
Registered User
 
Join Date: Aug 2013
Last Activity: 20 August 2013, 3:42 PM EDT
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Thanks for the expanded explanation

I had tried something similar and got a syntax error (about a missing conjunction) as you said:

Code:
-rw-r--r--    1 root     system            0 Aug 16 11:20 test
-rw-r--r--    1 root     system            0 Aug 16 11:20 2test
-rw-r--r--    1 root     system            0 Aug 16 11:20 2test2
-rw-r--r--    1 root     system            0 Aug 16 11:20 22test
-rw-r--r--    1 root     system            0 Aug 16 11:20 22test22

Thanks for teaching a man to fish.
Sponsored Links
    #6  
Old 08-16-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 24 October 2014, 4:38 PM EDT
Location: Saskatchewan
Posts: 19,683
Thanks: 823
Thanked 3,352 Times in 3,139 Posts
Quote:
Originally Posted by g.j.huebschman View Post
I can also see that I don't understand the difference between the shell expanding the wildcards and the command expanding the wildcards.
When in doubt, see what it does when you feed it into echo. If anything gets changed, it's the shell that's doing it, not echo, because echo is stupid and dumb and translates nothing.


Code:
$ touch abcdefg # Create empty file
$ echo a* # Shell turns a* into abcdefg BEFORE echo is run
abcdefg

$ echo "a*" # Quotes prevent the shell from changing it
a*

$ rm abcdefg # Remove file, so its no longer found
$ echo a* # Since there are no files beginning with a, the shell leaves it as a*
a*

$


Last edited by Corona688; 08-16-2013 at 04:42 PM..
The Following User Says Thank You to Corona688 For This Useful Post:
g.j.huebschman (08-20-2013)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
getting value between double quote BeefStu Shell Programming and Scripting 4 09-28-2011 03:16 PM
replacing a quote in some lines with multiple quote fields wradwan Shell Programming and Scripting 3 06-02-2010 06:53 AM
Regex in grep to match all lines ending with a double quote (") OR a single quote (') NanJ Shell Programming and Scripting 6 08-26-2009 09:28 AM
double-quote inside double-quote indraf Shell Programming and Scripting 3 10-20-2008 05:53 AM
Capturing Data between first quote and next quote scorp_rahul23 Shell Programming and Scripting 4 09-26-2008 08:42 AM



All times are GMT -4. The time now is 12:00 PM.