- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- getopt and parameters with space or "
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
12-15-2016 07:10 AM
12-15-2016 07:10 AM
getopt and parameters with space or "
Hi,
My script needs to accept this
myscript -o test -a -t preRefresh -v "echo "Hello world""
I'm using getopt.
The key -v gives this value: echo
I want echo "Hello world"
Any ideas ?
Kind regards,
Den
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2016 08:36 AM
12-15-2016 08:36 AM
Re: getopt and parameters with space or "
> My script needs to accept this
>
> myscript -o test -a -t preRefresh -v "echo "Hello world""
Good luck. Your (interactive) shell is processing those quotation
marks before "myscript" ever sees them.
> I'm using getopt.
Inside "myscript"? Doesn't matter.
> The key -v gives this value: echo
Actually, I'd expect >echo <, not >echo<, because that's what's
between your first pair of quotation marks.
> I want echo "Hello world"
That's possible, but not by simply nesting quotation marks. A
UNIX(-like) shell does not interpret nested quotation marks as nested.
For example:
mba$ echo fred
fred
No surprise.
mba$ echo "fred"
fred
That's "fred", and the shell eats the quotation marks.
mba$ echo "f"re"d"
fred
That's "f", re, and "d", and the shell eats all the quotation marks.
To get what you want, you could use backslashes to escape the normal
(shell) interpretation of (some) quotation marks:
mba$ echo "f\"re\"d"
f"re"d
Or, you could use apostrophes instead of quotation marks around the
whole expression:
mba$ echo 'f"re"d'
f"re"d
Of course, if your string includes apostrophes, then you have a
different set of escape/quotation problems to solve.
The critical detail is recognizing what is processing whom, and how
it interprets what it gets, and what the result is. In your case, your
interactive shell is interpreting those quotation marks before they ever
get to "myscript". For more details, see the documentation for your
interactive shell.
Note that on VMS, the DCL command-line interpreter uses a different
set of rules, and a kind of quotation nesting is possible there:
alp $ write sys$output "fred"
fred
alp $ write sys$output "f""re""d"
f"re"d
But (obviously) that's not a UNIX(-like) shell.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2016 09:05 AM
12-15-2016 09:05 AM
Re: getopt and parameters with space or "
Hi,
thanks for this answer.
Then ... what is the solution offered ? How may I pass my parameter to be recognized as the value I want to identify with the -v key ?
Best regards, Den.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2016 09:31 AM
12-15-2016 09:31 AM
Re: getopt and parameters with space or "
> Then ... what is the solution offered ? [...]
[...] -v "echo \"Hello world\""
[...] -v 'echo "Hello world"'
Apparently, that whole "Teach a man to fish" thing has limited
application.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2016 12:07 AM
12-16-2016 12:07 AM
Re: getopt and parameters with space or "
Hi,
Unfortunately it does not works!
I'm using this to parse:
while [ $# -gt 0 ];
do
case $1 in
-h)
HELP=YES
shift
;;
-i)
inDELPHIX_OBJECT=$2
shift 2
;;
-t)
inHOOK_TYPE=$2
shift 2
;;
-v)
inHOOK_COMMAND=$2
shift 2
;;
-a)
inHOOK_ACTION="ADD_HOOK"
shift
;;
-x)
inHOOK_ACTION="DELETE_HOOK"
shift
;;
-n)
inHOOK_POSITION=$2
shift 2
;;
--)
shift
break
;;
*)
ErreurArguments
;;
esac
done
Kind regards, Den.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2016 07:19 AM
12-16-2016 07:19 AM
Re: getopt and parameters with space or "
> Unfortunately it does not works!
What, exactly, does not work? Define/explain "not work". As usual,
showing actual commands with their actual output can be more helpful
than vague descriptions of interpretations.
I added a "#!/bin/sh" to the beginning of the code you posted, and
this at the end:
echo " inHOOK_COMMAND: >${inHOOK_COMMAND}<"
Then:
pro3$ ./pa.sh -v "echo \"Hello world\""
inHOOK_COMMAND: >echo "Hello world"<
That looks like what I'd expect. Similarly:
pro3$ ./pa.sh -a -t preRefresh -v "echo \"Hello world\""
inHOOK_COMMAND: >echo "Hello world"<
I'll admit that your (partial) script works badly when one specifies
-o test
on its command line, but that's pretty easy to explain. (Especially
when I don't have an "ErreurArguments" function(?) in my script. I also
added a "break" statement after "ErreurArguments" in my script.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2016 09:45 PM - edited 12-18-2016 09:55 PM
12-18-2016 09:45 PM - edited 12-18-2016 09:55 PM
Re: getopt and parameters with space or "
>I'd expect >echo <, not >echo<, because that's what's between your first pair of quotation marks.
That doesn't matter, it's what's after the quotation marks, if no space, you should expect:
>echo Hello<
> I also added a "break" statement after "ErreurArguments"
You would need to add a "break 2" or a shift then break, so you don't loop.