[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bash question: what is the difference in the following?
- To: Yedidya Bar-david <didi@xxxxxxxxxxxxxx>
- Subject: Re: bash question: what is the difference in the following?
- From: Shaul Karl <shaulk@xxxxxxxxxxxxxx>
- Date: Tue, 18 Jul 2000 01:31:14 +0300
- cc: linux-il@xxxxxxxxxxxx
- Delivered-To: linux.org.il-linux-il@linux.org.il
- In-Reply-To: Message from Yedidya Bar-david <didi@math.tau.ac.il> of "Mon, 17 Jul 2000 01:01:03 +0300." <200007162201.BAA26917@lune.math.tau.ac.il>
- References: <200007162201.BAA26917@lune.math.tau.ac.il>
- Sender: linux-il-bounce@xxxxxxxxxxxxx
> Shaul Karl wrote:
> > > >
> > > > [08:40:06 /tmp]# DAEMON=powercom
> > > > [08:41:59 /tmp]# ARGUMENTS='-m "Advice Partner/King PR750" -s 00131581
> > > > /dev/ttyS1'
> > > > [08:42:09 /tmp]# echo $DAEMON $ARGUMENTS
> > > > powercom -m "Advice Partner/King PR750" -s 00131581 /dev/ttyS1
> > > > [08:42:17 /tmp]# `echo $DAEMON $ARGUMENTS`
> > > > Network UPS Tools - PowerCom UPS driver 0.01 (0.44.0-pre4)
> > > > Unable to open (1) Partner/King: No such file or directory
> > > > [08:42:25 /tmp]#
> > > >
> > >
> > > How about trying the following:
> > >
> > > `echo $DAEMON "$ARGUMENTS"`
> > >
> > > The outer back-quotes are unnecessary in this case (running from the
> > > command line) but I assume you want to put this in some script.
> > >
> > > The problem is, of course, that $ARGUMENTS gets separated by the shell
> > > into "Advice" "Parnet/King" "PR750". The extra quotes should do the
> > > trick.
> > >
> > > -- Nimrod.
> >
> >
> > It is protected with quotes ("") in the first place. Why will it get separated
> > by bash into 3 strings?
>
> from bash(1):
> Word Splitting
> The shell scans the results of parameter expansion, com
> mand substitution, and arithmetic expansion that did not
> occur within double quotes for word splitting.
>
> Of course, it is not trivial how to apply that to your example. As I
> understand, 'did not occur within double quotes' refers only to the
> original text, and not to 'the results of'.
> If you want to go over the whole Expansion process, I see no way other
> than rerun the shell, as in
> sh -c "$DAEMON $ARGUMENTS"
> (This will probably not be exactly what you need, but you see what I mean).
sh -c "$DAEMON $ARGUMENTS" is working.
But it is not what I need. I need it with something like `echo $DAEMON
$ARGUMENTS` because the final result should be to gives this to shell vars to
debian start-stop-daemon as in
start-stop-daemon --start --verbose --exec /sbin/$DAEMON -- $ARGUMENTS
Isn't there a way to prevent the shell from removing the quotes? Perhaps with
a more complicated structure of single and double quotes in the definition of
ARGUMENTS?
BTW: ps does not show the quotation:
[01:25:29 /tmp]# ps axf |grep powercom | grep -v grep
8739 pts/9 S 0:00 powercom -m Advice Partner/King PR750 -s 00131581
/dev/ttyS1
[01:26:02 /tmp]#
>
> > In any case, without the outer back-quotes that you put the DAEMON and
> > ARGUMENTS vars are simply being displayed. And with them I am getting the
> > previous behavior.
> >
> >
> > [23:26:14 /tmp]# echo $DAEMON "$ARGUMENTS"
> > powercom -m "Advice Partner/King PR750" -s 00131581 /dev/ttyS1
> > [23:31:53 /tmp]# echo $DAEMON $ARGUMENTS
> > powercom -m "Advice Partner/King PR750" -s 00131581 /dev/ttyS1
> > [23:31:59 /tmp]# `echo $DAEMON "$ARGUMENTS"`
> > Network UPS Tools - PowerCom UPS driver 0.01 (0.44.0-pre4)
> > Unable to open (1) Partner/King: No such file or directory
> > [23:32:14 /tmp]#
> >
> >
> > In case it might give someone a hint, here is the main part of powercom.c. The
> > command line arguments get parsed here.
> >
> > [23:35:20 models]$ grep main powercom.c -A 56
> > int main (int argc, char **argv)
> > {
> > char *portname, *prog, raw_data[NUM_OF_BYTES_FROM_UPS],
> > tmp[256], *ups_model = 0, *ups_serial_num = 0;
> > int i;
> >
> > printf ("Network UPS Tools - PowerCom UPS driver 0.01 (%s)\n",
> > UPS_VERSION);
> > openlog ("powercom", LOG_PID, LOG_FACILITY);
> >
> > prog = argv[0];
> >
> > if (argc == 1) {
> > printf("Error: no device specified!\n");
> > help (prog);
> > }
> >
> > while ((i = getopt(argc, argv, "+hd:k:m:s:")) != EOF) {
> > switch (i) {
> > case 'd':
> > sddelay = atoi(optarg);
> > break;
> > case 'h':
> > help(prog);
> > break;
> > case 'k':
> > forceshutdown(optarg);
> > break;
> > case 'm':
> > ups_model = optarg;
> > break;
> > case 's':
> > ups_serial_num = optarg;
> > break;
> > default:
> > help(prog);
> > break;
> > }
> > }
> >
> > argc -= optind;
> > argv += optind;
> >
> > droproot();
> >
> > portname = NULL;
> > for (i = strlen(argv[0]); i >= 0; i--)
> > if (argv[0][i] == '/') {
> > portname = &argv[0][i+1];
> > break;
> > }
> >
> > if (portname == NULL) {
> > printf ("Unable to abbreviate %s\n", argv[0]);
> > exit (1);
> > }
> >
> > [23:35:27 models]$
> >
> >
> > --
> >
> > -- Shaul Karl <shaulk@israsrv.net.il>
> >
> > Donate free food to the world's hungry: see http://www.thehungersite.com
> >
> >
> >
> > =================================================================
> > To unsubscribe, send mail to linux-il-request@linux.org.il with
> > the word "unsubscribe" in the message body, e.g., run the command
> > echo unsubscribe | mail linux-il-request@linux.org.il
> >
>
> didi
--
-- Shaul Karl <shaulk@israsrv.net.il>
Donate free food to the world's hungry: see http://www.thehungersite.com
To unsubscribe, send mail to linux-il-request@linux.org.il with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail linux-il-request@linux.org.il