Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Ubuntu This forum is for the discussion of Ubuntu Linux.


  Search this Thread
Old 08-03-2007, 01:47 PM   #1
Registered: Oct 2004
Posts: 98

Rep: Reputation: 15
Question Bash script says command not found - why?

I have a simple script that should work:


STR = "Hello World!"
echo $str
Here is what I get when I run it (note that I did CHMOD 755 so it will run)

myname@myhost:~$ ./test
./test: Line 3: STR: command not found

Why is it doing this? It works if I put just

echo "Hello World"

in the script. But it won't work using a variable.

I'm using Ubuntu Server 6.06.1.

This is odd.
Old 08-03-2007, 01:54 PM   #2
ReliaFree Maintainer
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,812
Blog Entries: 1

Rep: Reputation: 259Reputation: 259Reputation: 259
Try removing the white spaces around the = so it looks like this
str="Hello World"
echo $str
Old 08-03-2007, 02:00 PM   #3
Registered: Dec 2005
Location: Edmonton
Distribution: BLFS, Gentoo
Posts: 353

Rep: Reputation: 32
If you're trying to learn scripting, try a google search with words like "bash scripting guide" and you will several useful resources.

STR = "Hello World!"
Remove the spaces around the = sign, like this:

STR="Hello World!"
There still will be a problem in your script. Unlike windoz, Linux is case sensitive. Therefore $str is not the same as STR. Change the last line like this:

echo $STR
Old 08-03-2007, 02:19 PM   #4
Registered: Oct 2004
Posts: 98

Original Poster
Rep: Reputation: 15
Thanks all. I haven't worked with bash in a couple years or so and hadn't remembered that there should be no whitespace. It works.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Bash: command not found! Adil_uk Linux - General 14 04-09-2012 01:04 AM
bash: g++: command not found m_lp_ql_m Linux - Software 8 07-08-2010 01:45 PM
bash: rpm: command not found && sudo: alien: command not found Java_Code Ubuntu 7 07-27-2006 11:57 PM
Trying to write a bash script -- :Command not found? bpottle Linux - Software 7 06-10-2006 06:11 PM
Bash Script; command not found twintornado Programming 2 06-01-2005 09:59 AM > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 03:00 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration