LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-29-2008, 10:06 AM   #1
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
awk in a bash script drive me mad


Hello,

I want to get the SVN repository URL from a directory, for this purpose I make:
Code:
URL=`svn info $LOCAL_DIR | grep URL | awk -F" : " ' { print $2 } '`
It works fine when called from a console, but if i put this line into a bash script file, it complains with:
Code:
./svn_diff_dir.sh: line 14:  awk: command not found
even if I replace awk with /bin/gawk (on fedora core 8 this is the "true" awk program)...

Could anybody point me the difference for executing this line into the script?

Thanks.
 
Old 10-29-2008, 10:30 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
What if you put echo $PATH at the beginning of your script? Is the path of the awk executable displayed in the PATH seen by the script?
 
Old 10-29-2008, 10:35 AM   #3
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Original Poster
Rep: Reputation: 50
Yes the path is OK
 
Old 10-29-2008, 10:50 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Please, can you post the script (or the first 20 lines of it)?
 
Old 10-29-2008, 11:24 AM   #5
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Original Poster
Rep: Reputation: 50
Here is my script:
Code:
#! /bin/bash

LOCAL_DIR=$1
COMMENT="test"
USERNAME="--username jf.argentino"
PASSWORD="--password oseanjfa"

if [ -z $LOCAL_DIR ]; then
   LOCAL_DIR="."
fi

if [ ! -d $LOCAL_DIR ]; then
   echo "ERROR: $LOCAL_DIR isn't a directory"
   exit
fi

URL=`svn info $LOCAL_DIR | grep URL | awk  -F ' : ' ' { print $2 } '`

TEMP_DIR=`mktemp -d`

svn co $URL $TEMP_DIR

meld $LOCAL_DIR $TEMP_DIR

ADDED=`svn status $TEMP_DIR | grep ? | awk ' { print $2 } ' `
svn add $ADDED
svn commit $TEMP_DIR -m $COMMENT $USERNAME $PASSWORD

rm -rf $TEMP_DIR

svn update $LOCAL_DIR
A really strange thing is that the following line works:
Code:
ADDED=`svn status $TEMP_DIR | grep ? | awk ' { print $2 } ' `
So I think the problem is due to the "-F" argument, but for now I don't understand that much...
 
Old 10-29-2008, 11:46 AM   #6
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
There is a slight typo error on the first line, it shouldn't have space between #! and /bin/bash
(eg: #!/bin/bash)
 
Old 10-29-2008, 12:22 PM   #7
abolishtheun
Member
 
Registered: Mar 2008
Posts: 183

Rep: Reputation: 31
I think a space between the #! and /bin/bash is allowed... isn't it?
 
Old 10-29-2008, 01:02 PM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Indeed the space between #! and /bin/bash is allowed. If you try to put the following in a BASH script:
Code:
#! /usr/bin/python
it will spit out a python's error.

Regarding the "command not found" issue, the script seems correct, but what puzzles me is the error message:
Code:
./svn_diff_dir.sh: line 14:  awk: command not found
You should not have a double space between "14:" and "awk:". Maybe some control character has been written unintentionally? Have you tried to delete the entire line and rewrite it?
 
Old 10-29-2008, 01:12 PM   #9
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Original Poster
Rep: Reputation: 50
Quote:
You should not have a double space between "14:" and "awk:". Maybe some control character has been written unintentionally? Have you tried to delete the entire line and rewrite it?
I just do that... And now what I've got is:
Code:
./svn_diff_dir.sh: line 17:  grep: command not found
./svn_diff_dir.sh: line 17:  awk: command not found
 
Old 10-29-2008, 01:16 PM   #10
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Original Poster
Rep: Reputation: 50
Quote:
Maybe some control character has been written unintentionally?
How to loose one hour or two!!! I take a look to my script with an hexeditor, and there's strange characters into the line that I remove and now it work great!
I'm certainly too tired to pipe 3 different command into the same line without typo, and this twice !
By the way thank for your help
 
Old 10-29-2008, 01:19 PM   #11
abolishtheun
Member
 
Registered: Mar 2008
Posts: 183

Rep: Reputation: 31
what editor are you using? now I'm afraid my own code has random control characters embedded in it.
 
Old 10-29-2008, 01:23 PM   #12
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You're welcome!
 
  


Reply



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
Problem with AWK in a BASH script geek_man Programming 4 01-20-2008 07:16 PM
Putting awk in bash script the_imax Programming 9 05-12-2007 03:50 PM
Using global variable in awk (bash script) kopeda Programming 2 04-24-2007 01:47 AM
can awk see bash script arguments ? sharapchi Programming 7 12-14-2006 08:03 PM
Bash script question (grep and awk) hamish Linux - Software 6 04-06-2005 03:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:08 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
Open Source Consulting | Domain Registration