I'm using a script for Linux and for Solaris (Nexenta).
This line works on Linux, but not on solaris (but when run from shell it works):
cat "pg_hba.conf" | sed "0,/^local/{s/md5/trust/}"
The error message is:
sed: command garbled: 0,/^local/{s/md5/trust/}
After some research, I found out that the sed
that bash uses in the script is different.
from shell: /usr/bin/sed
from script: /usr/sun/bin/sed
I want to make the script use /usr/bin/sed
.
What I tried to do:
- call
sed
with full path. Same results. It seems that it is still uses the othersed
... - tried to call it via
bash -l
. Same results. - tried to declare a different command:
S=/usr/lib/sed
and use$S
instead. Same results. - checked PATH - both cmd and script have
/usr/bin
in it. - Tried replacing the double quotes to single. Same results.
tried running the sed with -r flag. Output is :
# /usr/xpg4/bin/sed -r /usr/xpg4/bin/sed: illegal option -- r Usage: sed [-n] script [file...] sed [-n] [-e script]...[-f script_file]...[file...]
HELP??
What I need to do is to replace the first match of "md5" with "trust" on the first line that starts with "local"). I know I can do it otherwise but I the sed
issue is itching me too much!
EDIT:
I hope this makes a little order...
- PATH from login shell =
/usr/local/ctera/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/ctera/apache-ant-1.8.2/bin
- PATH from script =
/usr/sbin:/usr/bin:/usr/local/ctera/apache-ant-1.8.2/bin:/usr/local/ctera/apache-ant-1.8.2/bin
- PATH from script when
PATH=$(command -p getconf PATH):$PATH
is called =/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/opt/SUNWspro/bin:/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:/opt/SUNWspro/bin:/usr/sbin:/usr/bin:/usr/local/ctera/apache-ant-1.8.2/bin:/usr/local/ctera/apache-ant-1.8.2/bin
truss -f sed
from login shell calls/usr/bin/sed
truss -f sed
from script calls/usr/sun/bin/sed
truss -f /usr/bin/sed
from script calls/usr/sun/bin/sed
!!!- After setting
PATH=$(command -p getconf PATH):$PATH
:
7.1truss -f sed
from script calls/usr/xpg4/bin/sed
7.2truss -f /usr/bin/sed
from script calls/usr/sun/bin/sed
!!!
MORE INFO:
Commands output: (run both from shell prompt and from within the script)
truss -ft execve /usr/bin/sed q
as shell command:
8604: execve("/usr/bin/sed", 0x08047D20, 0x08047D2C) argc = 2
from script:
8545: execve("/usr/sun/bin/sed", 0x08047768, 0x08047774) argc = 2
file /usr/bin/sed
as shell command:
/usr/bin/sed: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), stripped
from script:
file: /usr/bin/sed zero size or zero entry ELF section - ELF capabilities ignored file: /usr/bin/sed: can't read ELF header /usr/bin/sed: data
ls -l /usr/bin/sed
as shell command:
-rwxr-xr-x 1 root root 96440 May 31 2008 /usr/bin/sed
from script:
-rwxr-xr-x 1 root root 96440 May 31 2008 /usr/bin/sed
ls -ld $(type -pa sed)
as shell command:
-rwxr-xr-x 1 root root 96440 May 31 2008 /bin/sed -rwxr-xr-x 1 root root 96440 May 31 2008 /usr/bin/sed
from script:
-rwxr-xr-x 1 root root 96440 May 31 2008 /usr/bin/sed
md5sum $(type -pa sed)
as shell command:
385361c5111226c8eac8e25b53fed29c /bin/sed 385361c5111226c8eac8e25b53fed29c /usr/bin/sed
from script:
385361c5111226c8eac8e25b53fed29c /usr/bin/sed
The script is invoced by JAVA code.
uname -a
SunOS cteraportal 5.11 NexentaOS_134f i86pc i386 i86pc Solaris
This might add info about the
sed
version on my machine~# ll `find / -name sed` -rwxr-xr-x 1 root root 96440 May 31 2008 /usr/bin/sed -r-xr-xr-x 1 root bin 35656 Sep 7 2010 /usr/sun/bin/sed -r-xr-xr-x 1 root bin 32104 Sep 7 2010 /usr/ucb/sed -r-xr-xr-x 1 root bin 35636 Sep 7 2010 /usr/xpg4/bin/sed /usr/share/doc/sed: total 113 -rw-r--r-- 1 root root 168 Jun 21 2005 AUTHORS.gz -rw-r--r-- 1 root root 2507 Jun 21 2005 BUGS.gz -rw-r--r-- 1 root root 6584 Feb 3 2006 NEWS.gz -rw-r--r-- 1 root root 285 Jun 21 2005 README.gz -rw-r--r-- 1 root root 1071 Jan 12 2006 THANKS.gz -rw-r--r-- 1 root root 4806 May 31 2008 changelog.Debian.gz -rw-r--r-- 1 root root 32312 Feb 3 2006 changelog.gz -rw-r--r-- 1 root root 796 May 31 2008 copyright drwxr-xr-x 2 root root 3 May 30 2011 examples drwxr-xr-x 2 root root 3 May 30 2011 sed-4.1.5 -rw-r--r-- 1 root root 56538 May 31 2008 sedfaq.txt.gz
sed
command may be syntactically incorrect. Usually when you callsed
it would be followed by a flag. For example:sed 's/cat/dog/g'
– ryekayo Aug 18 '14 at 15:500,
is supposed to do? – ryekayo Aug 18 '14 at 15:54/usr/lib/sed '0,/^local/{s/trust/md5/}'
works at the shell prompt, but not in a script? – Stéphane Chazelas Aug 18 '14 at 16:08PATH
environment variable? It's not enough to know that/usr/bin
is on it, it matters what else is there and in what order. Are you sure you have a/usr/lib/sed
? That's highly unusual. And what's this aboutilligal option
— did you copy-paste that or did you mis-type it? Always copy-paste. – Gilles 'SO- stop being evil' Aug 18 '14 at 21:22truss -ft execve /usr/bin/sed q
, offile /usr/bin/sed
, ofls -l /usr/bin/sed
. oftype -a sed
? , ofls -ld $(type -a sed)
and ofmd5sum $(type -a sed)
? – Stéphane Chazelas Aug 19 '14 at 09:17$(type -pa sed)
above (assumingbash
is the shell). – Stéphane Chazelas Aug 19 '14 at 09:37/usr/bin/sed
somewhere? What version of Nexenta is it? I don't understand howtruss /usr/bin/sed
can not showexecve("/usr/bin/sed",...)
– Stéphane Chazelas Aug 19 '14 at 15:34sed
is called... The same problematic sed replacement works via shell prompt. So there is a "good" sed on my system, which is the/usr/bin/sed
, that just isn't called in the script. Some magic going on... – csny Aug 19 '14 at 15:56