TomCho
TomCho

Reputation: 3507

awk not being recognized after certain command

Here's a MWE:

#!/bin/bash
INFILE=$1
echo `echo $INFILE | awk '{print(substr($0,8,3))}'`

PATH=${INFILE%/*}
echo `echo $INFILE | awk '{print(substr($0,8,3))}'`
exit

Apparently the first awkcommand runs fine, but in the second command bash doesn't recognize awkanymore! This is what I get running it (assuming that f_mwe.sh is the name of the file):

$ ./f_mwe.sh /home/something/path/this_is_the_name.txt
ome
./f_mwe.sh: line 31: awk: command not found

$

I have tried defining /bin/sh and ksh at the beginning also but got the same results. I have no idea what's causing this.

Any help is appreciated.

Upvotes: 1

Views: 297

Answers (1)

ojblass
ojblass

Reputation: 21620

You are overwriting the PATH variable and not appending to it I believe. You should append to the PATH variable.

Upvotes: 4

Related Questions