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
Forums
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
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
12-14-2006 09:57 PM
12-14-2006 09:57 PM
Could you please let me know what will below command do:
if [ -f ${2} -o "$(whence $2)" != "" ];
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2006 10:07 PM
12-14-2006 10:07 PM
SolutionThe statement tests whether or not the second argument ($2) passed to the script or to a script function, represents a file ('-f'), *or* if the name of the argument represents a command.
# whence date
/usr/bin/date
# [ -f date ] && echo ok || echo not_ok
not_ok
# [ -f /usr/bin/date ] && echo ok
ok
The above shows that an argument of 'date' does not represent a file, but 'whence date' returns '/usr/bin/date' and thus the expression (statement) would evaluate to true.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2006 10:08 PM
12-14-2006 10:08 PM
Re: whence
It checks whether the file in $2 exsits or not
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2006 10:16 PM
12-14-2006 10:16 PM
Re: whence
if second parameter is a local file or a command then the condition would return true.
Example:
#!/usr/bin/sh
# My name is a.sh
if [ -f ${1} -o "$(whence $1)" != "" ]
then
echo "valid file or command"
fi
First test:
$ ./a.sh date
valid file or command
Second test:
$ ./a.sh fred
$
Third test:
$ touch fred
$ ./a.sh fred
valid file or command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2006 10:36 PM
12-14-2006 10:36 PM