[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bash question: what is the difference in the following?
> >
> > [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?
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