- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: ksh: use find command with quoting
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2014 05:32 AM
06-12-2014 05:32 AM
ksh: use find command with quotings
hello,
i want to make "find" variable with different options and store this options in a shell script variable.
example ( find a directory named "testdir" ) :
mkdir testdir find . -type d -name "testdir"
now variable and it doesn't work:
find_opts="-type d -name \"testdir\"" find . ${find_opts} -print
only with eval it works
find . $( eval echo ${find_opts} ) -print
Output:
./testdir
- do i need to quote the name of the directory ( -name "testdir"
- does a easier way exist ?
regards
- Tags:
- quoting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2014 07:16 AM
06-12-2014 07:16 AM
Re: ksh: use find command with quotings
If you are using a complete directory name in your find command, then no you should not need to quote. Quotes will come into play if you use a wildcard as part of the directory name.
For exampe --
No need to quote this:
# find /dir -type d -name some_other_dir
Quotes needed:
# find /dir -type d -name "some_other*"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2014 11:44 PM - edited 06-12-2014 11:44 PM
06-12-2014 11:44 PM - edited 06-12-2014 11:44 PM
Re: ksh: use find command with quoting
>do I need to quote the name of the directory (-name "testdir")
No.
$ find_opts="-type d -name \"testdir\""
$ printenv $find_opts
the count is 5
printenv
-type
d
-name
"testdir"
$ find_opts="-type d -name testdir"
$ printenv $find_opts
the count is 5
printenv
-type
d
-name
testdir
Spaces are a problem:
$ find_opts="-type d -name test dir"
$ printenv $find_opts
the count is 6
printenv
-type
d
-name
test
dir
Wildcards may be a problem:
$ find_opts="-type d -name testdir*"
$ mkdir testdir2
$ printenv $find_opts
the count is 5
printenv
-type
d
-name
testdir2
Quoting of var use doesn't help:
$ find_opts='-type d -name testdir*'
$ printenv "$find_opts"
the count is 2
printenv
-type d -name testdir*
This doesn't help:
$ find_opts='-type d -name testdir*'
$ printenv $find_opts
the count is 5
printenv
-type
d
-name
testdir2
You could use arrays which can maintain quoting:
$ set -A find_opts -- -type d -name "testdir*"
$ printenv "${find_opts[@]}"
the count is 5
printenv
-type
d
-name
testdir*
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2014 07:33 AM
06-18-2014 07:33 AM
Re: ksh: use find command with quoting
hello,
printenv only works with following steps ( ksh )
$ find_opts="-type d -name test dir"
$ export find_opts
$ printenv $find_opts
and the output is only in one line
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2014 11:44 PM
06-18-2014 11:44 PM
Re: ksh: use find command with quoting
>printenv only works with following steps
Sorry, printenv is my own program, not printenv(1).
It also allows me to see what is passed on the command line.