- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to keep special meaning "*" inside a script
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
06-02-2003 05:58 AM
06-02-2003 05:58 AM
I want to execute the following command inside a script but it doesn't work because the special character "*" lose its special meaning inside a script.
...
if test -f /tmp/ffin*
...
Has anyone any idea?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2003 06:03 AM
06-02-2003 06:03 AM
Re: How to keep special meaning "*" inside a script
Escape the asterisk with a backslash:
# touch /tmp/my\*file
# rm /tmp/my\*file
...are examples of this.
# if test -f /tmp/ffin\*
...would test for the presence of a file named '/tmp/ffin*'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2003 06:04 AM
06-02-2003 06:04 AM
Re: How to keep special meaning "*" inside a script
if [ -f "/tmp/ffin*"]
then.....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2003 06:04 AM
06-02-2003 06:04 AM
Re: How to keep special meaning "*" inside a script
..../tmp/ffin\* ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2003 06:15 AM
06-02-2003 06:15 AM
Re: How to keep special meaning "*" inside a script
I just want to keep the meaning of "*".
I want to know if there are files with the pattern "ffin". For example, ffin0202.txt or ffin0304.txt, ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2003 06:15 AM
06-02-2003 06:15 AM
Re: How to keep special meaning "*" inside a script
Hi,
\* will keep metacharacter"*" anywhere
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2003 06:17 AM
06-02-2003 06:17 AM
Re: How to keep special meaning "*" inside a script
Another way is to use single quotes.
# touch '/tmp/my*file'
# rm '/tmp/my*file'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2003 06:21 AM
06-02-2003 06:21 AM
Re: How to keep special meaning "*" inside a script
Use the backslash (\) before the *.
Regards,
DR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2003 06:24 AM
06-02-2003 06:24 AM
Re: How to keep special meaning "*" inside a script
I resolved a similar question in
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xfc075ec05a7ad711abdc0090277a778c,00.html
try this:
if (ls /tmp/ffin* > /dev/null 2>&1) ; then echo Hi ; fi
Saludos
Frank.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2003 06:31 AM
06-02-2003 06:31 AM
Re: How to keep special meaning "*" inside a script
..
if (($(ls /tmp/ffin*|wc -l) > 1))
...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2003 06:32 AM
06-02-2003 06:32 AM
SolutionDo you mean that you want to disable or enable globbing (file name generation). If so:
set -f
...disables shell file name generation.
set +f
...enables shell file name generation.
You can certainly choose the option you want inside a script to make it differ (or not) from your shell environent.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2003 07:00 AM
06-02-2003 07:00 AM
Re: How to keep special meaning "*" inside a script
You perhaps want to do something if there is any files. Try the following:
for file in `ls /tmp/ffin* 2>/dev/null`
do
echo $file
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2003 06:47 AM
06-04-2003 06:47 AM
Re: How to keep special meaning "*" inside a script
Try the following :
if [ -f /tmp/ffin* ]; then
echo 'Found files'
fi
regards,
= Mike =
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2003 07:25 AM
06-04-2003 07:25 AM
Re: How to keep special meaning "*" inside a script
If filename generation is active, shell will replace your original line when it is going to be executed:
if test -f /tmp/ffin*
for
if test -f /tmp/ffin02.txt /tmp/ffin09 /tmp/ffin.old
if there are filenames that match the pattern /tmp/ffin*
If not shell will keep the original line:
if test -f /tmp/ffin*
and test will check if /tmp/ffin* file exist (test will not expand the metacharacter *).
Thus, I think that, if file name generation is on, your script would run fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2003 07:53 AM
06-04-2003 07:53 AM
Re: How to keep special meaning "*" inside a script
I wanted to enable file name generation. The problem was that I had the next parameter at the begin of the script:
#! /bin/sh -f
Next time, I'll send you the full script for detailed analysis ;-)