The problem is the placement of the closing back-quote `
in the command:
export PATH=`echo ${PATH} | awk -v RS=: -v ORS=: '/SDE/ {next} {print}'` | sed 's/:*$//'
If you used the recommended $(...)
notation, you'd see that this is equivalent to:
export PATH=$(echo ${PATH} | awk -v RS=: -v ORS=: '/SDE/ {next} {print}') | sed 's/:*$//'
which pipes the output of the export
operation to sed
, but export
is silent.
Use:
export PATH=$(echo ${PATH} | awk -v RS=: -v ORS=: '/SDE/ {next} {print}' | sed 's/:*$//')
I have fixed the answer from which the erroneous command was copied verbatim. As tripleee notes in a comment, I'm not wholly convinced by the awk
solution, but the question was 'what was wrong with the code' and the answer is 'where the back-quotes are placed'. The awk
script does handle removing elements of a PATH at any position in the PATH; the sed
script simply ensures there is no trailing :
so that there is no implicit use of the current directory at the end of the PATH.
See also: How do I manipulate PATH elements in shell scripts and the clnpath
script at How to keep from duplicating PATH variable in csh
— the script is for POSIX-ish shells like the Bourne, Korn, Bash shells, despite the question's subject. One difference between clnpath
and the notation used here is that clnpath
only removes full pathnames; it does not attempt to do partial path element matching:
export PATH=$(clnpath $PATH /opt/SDE/bin)
if the path element to be removed was /opt/SDE/bin
. Note that clnpath
can be used to maintain LD_LIBRARY_PATH
, CDPATH
, MANPATH
and any other path-like variable; so can the awk
invocation, of course.
I note in passing that that the /SDE/
pattern in the awk
script will remove /opt/USDER/bin
; the slashes in the regex have nothing to do with slashes in the pathname.