- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Shell script filename expansion
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
02-18-2002 09:56 AM
02-18-2002 09:56 AM
After a few search in the forum, I would like to do a wrapper for a unix command and I want to pass /*/zaza as script parameter and the script resend this parameter to the unix command without expanding the *....
Please help wanted....
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2002 10:02 AM
02-18-2002 10:02 AM
Re: Shell script filename expansion
/\*/zaza
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2002 10:06 AM
02-18-2002 10:06 AM
Re: Shell script filename expansion
What you need to do is quote the parameter, all the time. For example if your script is named test. The user will have to type:
test "/*/params"
This will make sure that the shell won't expand it. Then in the script you will also quote the parameter when you want to resend it to a unix command:
test2 "$1"
Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2002 10:08 AM
02-18-2002 10:08 AM
Solutionyou need to stop the shell from evaluating the wildcard, so the script must be called with quotes.
script '/*/zaza'
inside the script $1 will be '/*/zaza' WITHOUT the quotes.
Since the line in your script will be evaluated by a shell again, you need to re-insert quotes. But plainly reinserting quotes might hinder the shell from evaluating the $-sign to expand the parameter so you need to use double quoutes, therefore the call inside your script needs to be
call_inside_script "$1"
See the following to explain the quotes:
# export HELLO='*'
# echo $HELLO
Mail SD_CDROM a adabas b bin c cn_tmp dev etc home lib lost+found lsof-4.55-sd-11.00.depot mapvg01.map net nfs_mount omni omnicopy r
# echo '$HELLO'
$HELLO
# echo "$HELLO"
*
Hope this helps
Volker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2002 10:17 AM
02-18-2002 10:17 AM
Re: Shell script filename expansion
----------------------------
My sample script: zazou.sh
----------------------------
#!/bin/sh
echo $1
----------------------------
Sure: echo /\*/zaza
return: /*/zaza
But
./zazou.sh /\*/zaza
return: /a01/zaza /a02/zaza /a03/zaza
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2002 10:19 AM
02-18-2002 10:19 AM
Re: Shell script filename expansion
# echo $H should give
/*/zaza
g`d luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2002 10:26 AM
02-18-2002 10:26 AM
Re: Shell script filename expansion
that is exactly correct.
If you want the script to display
/*/zaza
You need to use
echo "$1"
inside the script.
In
echo $1
the parameter $1 will be evaluated and after that the wildcard will be expanded.
Volker
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2002 07:54 PM
02-18-2002 07:54 PM
Re: Shell script filename expansion
Doing a
set -f
will turn off filename expansion. It will remained turned off till you issue a
set +f
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2002 10:54 PM
02-18-2002 10:54 PM
Re: Shell script filename expansion
quoting (masquerading) of special characters isn't as trivial as people often think! But if you know the rules, it can be very simple:
'string_to_quote'--> quotes every special character within...
"string_to_quote" -->quotes some special characters, but others are not quoted, within there is continuing variable substitution and command substitution, so the $- character and the ``backticks are not quoted!
\special_character -->quotes the character which is following directly, only one character!
The next thing you need to know is, how a shell interpretes a command line before it is executed:
the shell takes a look at the whole command line and seeks for special characters to be interpreted, like backticks for command substitution or a $-character for variable substitution. It is easy to find out how the command line looks like after interpreting but before execution:
set -o xtrace
command_line
set +o xtrace
set -o xtrace turns on a debugging mode which shows you the command line after interpretation with a + character in front of the line. Then you see the output of the command line.
set +o turns of the debugging mode. These two lines at the beginning and at the end of your scripts can be very helpful when searching for errors!
example:
var=value
set -o xtrace
echo '$var' "$var" \$var (RETURN)
+ echo $var value $var
$var value $var
Allways stay on the bright side of life!
Peter