Click to See Complete Forum and Search --> : bash scripting questions
karthik
06-19-2003, 12:19 AM
hello everyone,
i was reading through some of the init scripts and came across these BASH syntaxes and could'nt find much info as to what they mean ..
local gotbase= force=
local base= user= nice= bg= pid=
and also
[ -n "${pid:-}" -a -z "${force:-}" ] && return
In the first code segment after the "=" sign there are no values assigned to the variable, so what are these variables initialized to ???
In the second code segment what does ${pid:-} mean ?
thanx for the help
irlandes
06-19-2003, 12:58 AM
Um, using a borrowed computer with Win, but by memory I think pid is like the process number (process i.d.??) . Each process has a different pid number. If I am wrong, you will get lots of help. Hee, hee.
Sepero
06-19-2003, 06:02 AM
# VAR="sample variable"
# echo $VAR
sample variable
# VAR=
# echo $VAR
# echo "${pid:-}"
#
That's what I get on my system. Hope it helps. :)
dchidelf
06-19-2003, 09:03 AM
${var:-value} means use $var if it is defined, otherwise use "value".
${var:-} doesn't seem to make sense, because if var is not defined it will use an undefined string...not much of a fall back.
arn0ld
06-19-2003, 06:03 PM
reminded me of perl, but i didn't know - so,
man perl
searched for local[^e], found it
karthik
06-19-2003, 06:28 PM
the other code segment where there were declarations like :
basename=
When it is left balnk what are these variables initialized to ??
Coming up is another question :
HOW-TO read a integer value from a file. The file i am trying to read is : /var/run/*.pid , anyfile in there. I am trying to read the process id !!! how can i read this value into a variable ??
TIA
karthik
arn0ld
06-19-2003, 08:01 PM
tried the man page again:
A variable may be assigned to by a statement of the form
name=[value]
If value is not given, the variable is assigned the null string.
bwkaz
06-19-2003, 11:28 PM
Originally posted by karthik
HOW-TO read a integer value from a file. The file i am trying to read is : /var/run/*.pid , anyfile in there. I am trying to read the process id !!! how can i read this value into a variable ?? myvarname=$(cat /var/run/filename.pid)
You can also use backticks around the cat command. And I think you can even do it without spawning another cat process, like so:
myvarname=$(</var/run/filename.pid)
but I'm not positive if that's supported in bash or not. If it is, you probably have to use $(...) instead of `...` (backticks).