LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-18-2010, 09:09 PM   #1
johnhelen
LQ Newbie
 
Registered: Sep 2009
Posts: 4

Rep: Reputation: 0
a simple bash command causing "bad variable name"


Hello all

When I run this command from shell, it runs ok
Quote:
export REVS=`svn info svn+ssh://svn.myone.ca/var/svn/story/trunk/lib |grep 'Last Changed Rev:'| awk -F: '{print $2}'`
However when I save it into a file called test.sh (of course, I chmod it with +x), I got error "export: 2: bad variable name"

Here is the file:

Quote:
#!/bin/bash
export REVS=`svn info svn+ssh://svn.myone.ca/var/svn/story/trunk/lib |grep 'Last Changed Rev:'| awk -F: '{print $2}'`
I am using ubuntu
Many thanks
john
 
Old 02-18-2010, 10:10 PM   #2
meetscott
Samhain Slackbuild Maintainer
 
Registered: Sep 2004
Location: Phoenix, AZ, USA
Distribution: Slackware
Posts: 411

Rep: Reputation: 43
That ought to work. I tried in on Slackware. Picked it apart step by step. It all looks good.

I am using bash. Verify that is the shell you are using. If it is, I see no difference. In fact, I was able to properly set the environment variable, $REVS, with the revision on my own svn repo.

To do that invoke the parent shell:
Code:
. ./test.sh
Then:
Code:
echo $REVS
Maybe Ubuntu is doing something different? Are they using dash instead of bash now?
Code:
echo $SHELL
It should output /bin/bash for bash and /bin/dash for dash. Maybe dash handles it differently? I'm grasping at straws here but perhaps even when you are forcing the #!/bin/bash maybe it is still picking up dash because that is installed and bash is not? I don't know, maybe dash would work anyway. This really looks okay, anyone with Ubuntu that can verify?

Last edited by meetscott; 02-19-2010 at 12:40 AM. Reason: left out "and" in my sentence.
 
Old 02-18-2010, 10:21 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
If you just copy-n-paste that (dual) 'line' into an editor, it will silently insert a hard newline between the lines. Use shift-j (in vim) to re-join into one line.
 
Old 02-18-2010, 10:34 PM   #4
meetscott
Samhain Slackbuild Maintainer
 
Registered: Sep 2004
Location: Phoenix, AZ, USA
Distribution: Slackware
Posts: 411

Rep: Reputation: 43
Quote:
Originally Posted by chrism01 View Post
If you just copy-n-paste that (dual) 'line' into an editor, it will silently insert a hard newline between the lines.
So? How does joining the lines change his intent? Or more importantly the shell interpretation? The #!/bin/bash should be on a line on its own. What am I not understanding here?

Did I just miss the joke? Okay, ha ha.
Quote:
Use shift-j (in vim) to re-join into one line.
It must be, because you are giving simple, irrelevant editor command lessons :-)
 
Old 02-18-2010, 11:03 PM   #5
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 707

Rep: Reputation: 55
Hello johnhelen,

Can you please paste the output of following ?
Code:
od -t c script.sh
As chrism01 mentioned, even I suspect there may be some new line character inserted in between.
 
Old 02-19-2010, 04:17 AM   #6
johnhelen
LQ Newbie
 
Registered: Sep 2009
Posts: 4

Original Poster
Rep: Reputation: 0
thanks but

The error happens only when I run with this command

sh test.sh

But it runs OK when I run with this command

./test.sh

I do not know why they are different

Thanks
john
 
Old 02-19-2010, 05:17 AM   #7
deadeyes
Member
 
Registered: Aug 2006
Posts: 609

Rep: Reputation: 79
Quote:
Originally Posted by johnhelen View Post
The error happens only when I run with this command

sh test.sh

But it runs OK when I run with this command

./test.sh

I do not know why they are different

Thanks
john
I am not sure but "export" is not a tool.
It is a builtin of Bash.

So this should work:
bash test.sh
I would expec "sh" does not know this.
Just test the bash test.sh command
And see if it works.
If it does, then this is normal behaviour and the above explains your error
 
1 members found this post helpful.
Old 02-20-2010, 01:21 AM   #8
johnhelen
LQ Newbie
 
Registered: Sep 2009
Posts: 4

Original Poster
Rep: Reputation: 0
thanks, I understand now

Yes, it works well with bash command
 
  


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
stuck on bash variable "expansion"? vornox00 Linux - Software 2 08-24-2008 09:06 PM
Bash variable problem: cURL -b parameter (string form e.g. "name=value;n2=v2") sithemac Other *NIX 3 07-09-2008 06:15 PM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
simple bash variable command itz2000 Programming 6 06-19-2006 08:24 PM
Bash Script: Problem running variable command containing "" Paasan Programming 2 01-21-2004 01:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:27 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