LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


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

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


I have a simple script that should work:

Code:
#!/bin/bash

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

#!/bin/bash
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
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
Try removing the white spaces around the = so it looks like this
Code:
#!/bin/sh
str="Hello World"
echo $str
 
Old 08-03-2007, 02:00 PM   #3
kevkim55
Member
 
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.

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

Quote:
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:

Quote:
echo $STR
 
Old 08-03-2007, 02:19 PM   #4
RavenLX
Member
 
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.
 
  


Reply


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

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