LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-05-2010, 04:31 PM   #1
axisofevil
LQ Newbie
 
Registered: Feb 2010
Posts: 14

Rep: Reputation: 0
/etc/init/d/functions - Bad Substitution error


I copied /etc/init.d/functions from a Redhat based system onto an embedded project and got
a "syntax error ( Bad Substitution ) on this line:
[ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"

when I do service crond start.

I found one redhat change which I put in ( commented 4 lines, added to "to here" ) , didn't help.

Whole function below:

__pids_var_run() {
local base=${1##*/}
local pid_file=${2:-/var/run/$base.pid}

pid=
if [ -f "$pid_file" ] ; then
local liine p

#https://fedorahosted.org/initscripts...b5fbb9a9e0b745
# read line < "$pid_file"
# for p in $line ; do
# [ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
# done
while : ; do
read line
[ -z "$line" ] && break
for p in $line ; do
echo $p
[ -z "${p//[0-9]/}" -a -d "/proc/$p" ] && pid="$pid $p"
done
done < "$pid_file"
# to here
if [ -n "$pid" ]; then
return 0
fi
return 1 # "Program is dead and /var/run pid file exists"
fi
return 3 # "Program is not running"
}

Ideas? Thanks, dB
 
Old 04-05-2010, 08:43 PM   #2
hi2arun
Member
 
Registered: Apr 2010
Distribution: Fedora
Posts: 109
Blog Entries: 4

Rep: Reputation: 34
Hi,

Check what that line expands to when executing the script

Quote:
sh -x /your/script/here
Are you using bash or any other shell?
 
Old 04-05-2010, 08:48 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
...or make the Bourne Again code Bourne shell compatible.
 
Old 04-05-2010, 09:24 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
I would be querying what this code does?

Quote:
"${p//[0-9]/}"
If I am reading this correctly, take the variable p and replace all occurrences of nothing "//"
with a boundary "[0-9]" and then an extra slash at the end that should not be there.

I could be wrong, but if this was copied from any other system, I am unsure how this would have ever worked?
 
Old 04-06-2010, 03:31 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by grail View Post
I would be querying what this code does?
In bash it removes all the digits from the value
Code:
c@CW8:~$ p=a1b2
c@CW8:~$ echo "${p//[0-9]/}"
ab
According to the GNU Bash Reference, it takes the variable p and replaces all occurrences of 0 to 9 with the null string. The trailing / is optional so ${p//[0-9]} would be functionally equivalent.

Last edited by catkin; 04-06-2010 at 03:32 AM. Reason: Prettification
 
Old 04-06-2010, 03:38 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,252

Rep: Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685Reputation: 2685
My apologise ... was in my own little world and looked at first reference:

Quote:
${string/substring/replacement}
And jumped to conclusions before reading:

Quote:
${string//substring/replacement}
Thanks for the re-education in RTFM <sheesh>
 
Old 04-06-2010, 06:17 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by grail View Post
Thanks for the re-education in RTFM <sheesh>
MMC, NP

That double / to indicate a global replacement is neither intuitive nor consistent with other usage AFAIK -- and making the final / optional doesn't help legibility. IMHO ${varname/match/replacement/g} would have been a better choice but there may, of course, have been factors in the decision that I wot not of.
 
Old 04-06-2010, 01:34 PM   #8
axisofevil
LQ Newbie
 
Registered: Feb 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks, all - it was running under another shell; its fine in bash.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
init.d script error bad interpreter snowmedia Red Hat 8 10-01-2011 07:16 PM
init-functions not found? MHaahr Debian 1 11-03-2007 04:52 AM
LFS Chapter 5.7 bad substitution MP123 Linux From Scratch 4 02-07-2007 03:08 AM
/etc/rc.d/init.d/functions? ccajina Slackware 4 11-26-2003 04:05 PM
I need help bad! The good ole No Init Found Error! Please Help! Gage33 Linux - General 0 10-05-2002 11:48 AM


All times are GMT -5. The time now is 06:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration