Score:0

awk command return not found on Ubuntu desktop but work well on Centos

cn flag

I create test.sh to read a file with content

item1:return1
item2:return2
...
item10:return10

test.sh content

VAR1=$1
VAR2= `grep "^${VAR1}:" /home/path/file | awk '{print $2;}'`

echo "${VAR2}";

run test

sh test.sh item1

return

: not found test.sh: 
: not found test.sh: 

When I run the same on Centos. return

return1

What's wrong with awk command ?

muru avatar
us flag
The output looks like the file has CRLF line endings. Did you edit on Windows at some point?
Score:0
vn flag

Nothing is wrong with awk command. Your issue is test.sh cannot be found as message shows. CentOS probably sets your path to PATH variable.

Run it as sh ./test.sh item1 (I assume test.sh is in your current directory)

Edit: I should have paid better attention to the script, : in grep is the issue This works

VAR1=$1
VAR2=`grep "${VAR1}\:" file | awk '{print $2}'`
echo "${VAR2}";

However, awk by default does not recognize : as a separator, I had to use

item1: return1
item2: return2

I have no idea how it could work on server or centos without this change

Shuch Saipay avatar
cn flag
You are correct test.sh is in my current directory. I tried with "sh ./test.sh item1" result is the same (a bit different) : not found2: ./test.sh: : not found5: ./test.sh:
vanadium avatar
cn flag
Make sure the executable bit is set
Shuch Saipay avatar
cn flag
Very strange I can run command very well on Ubuntu server version but can't run on Ubuntu desktop. All the same command.
marosg avatar
vn flag
Can you show output of `ls -l test.sh`?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.