- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Really weird script problem
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
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
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
тАО09-12-2005 01:04 PM
тАО09-12-2005 01:04 PM
#!/bin/sh
DATABASE=AP0041D
echo "1: [${DATABASE}]"
echo "2: [$DATABASE]"
echo 3: [${DATABASE}]
echo 4: [$DATABASE]
When run from any directory except / the output is:
$ ./quotes.sh
1: [AP0041D]
2: [AP0041D]
3: [AP0041D]
4: [AP0041D]
But from / the output is:
$ /tmp/quotes.sh
1: [AP0041D]
2: [AP0041D]
3: 1
4: 1
This only happens in HP-UX. I am using HP-UX 11.11 on PA-RISC. On several other versions of Unix (AIX and SuSE SLES 8), the output is the same as the first output even when run from /
Any ideas on how to prevent this inconsistency?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-12-2005 04:50 PM
тАО09-12-2005 04:50 PM
Re: Really weird script problem
-- Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-12-2005 04:56 PM
тАО09-12-2005 04:56 PM
Re: Really weird script problem
$ /tmp/quotes3.sh
DATABASE=AP0041D
+ DATABASE=AP0041D
echo "1: [${DATABASE}]"
+ echo 1: [AP0041D]
1: [AP0041D]
echo "2: [$DATABASE]"
+ echo 2: [AP0041D]
2: [AP0041D]
echo 3: [${DATABASE}]
+ echo 3: 1
3: 1
echo 4: [$DATABASE]
+ echo 4: 1
4: 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-12-2005 05:00 PM
тАО09-12-2005 05:00 PM
Re: Really weird script problem
Also make sure you define all required variables. Also in all variables, use ${XX}
Also set -u will error out, when it encounters unset variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-12-2005 10:20 PM
- Tags:
- quoting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-12-2005 10:35 PM
тАО09-12-2005 10:35 PM
Re: Really weird script problem
# what /sbin/sh
#!/bin/sh
DATABASE=""
echo "1: [${DATABASE}]"
echo "2: [$DATABASE]"
echo 3: [${DATABASE}]
echo 4: [$DATABASE]
#!/bin/sh
DATABASE="AP0041D"
echo "1: [${DATABASE}]"
echo "2: [$DATABASE]"
echo 3: [${DATABASE}]
echo 4: [$DATABASE]
#!/bin/sh
DATABASE=A
echo "1: [${DATABASE}]"
echo "2: [$DATABASE]"
echo 3: [${DATABASE}]
echo 4: [$DATABASE]
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-12-2005 10:40 PM
тАО09-12-2005 10:40 PM
Re: Really weird script problem
# /tmp/weird.sh (executed from root)
1: [AP0041D]
2: [AP0041D]
3: [AP0041D]
4: [AP0041D]
# touch 1
# /tmp/weird.sh
1: [AP0041D]
2: [AP0041D]
3: 1
4: 1
# rm -f 1
# /tmp/weird.sh
1: [AP0041D]
2: [AP0041D]
3: [AP0041D]
4: [AP0041D]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-12-2005 10:48 PM
тАО09-12-2005 10:48 PM
Re: Really weird script problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-12-2005 11:15 PM
тАО09-12-2005 11:15 PM
Re: Really weird script problem
i "unprotected mode" i.e. if not protected by quotes, e.g. lines 3 and 4 in your script - the shell expands wildcards to filenames in thecurrent directory.
Compare:
# ls [AP041D]
which will match the file names A, P, 0, 4, 1, or D in the directory you are in.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-12-2005 11:19 PM
тАО09-12-2005 11:19 PM
Re: Really weird script problem
"Braces are required when parameter is followed by a letter, digit, or underscore that should not be interpreted as part of its name or when a named parameter is subscripted. If parameter is one or more digits, it is a positional parameter.A positional parameter of more than one digit must be enclosed in braces."
And :
Inside double quote marks (""), parameter and command substitution occurs...
Meaning, last two echoes doesn't do the substitution...