If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Simple Unix Scripts

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-14-04, 06:42
mean2229 mean2229 is offline
Registered User
 
Join Date: Dec 2003
Location: San Mateo, Rizal, Philippines
Posts: 18
Question Simple Unix Scripts

Hi Gurus,

I am creating a simple shell scripts with the use of tilde or `

It seems that something wrong with my commands or configurations.
Please help me on this. I am figuring this out for at least a week now.
I still can't understand why this script produces an error.
Please see below.

filename: sample.sh and it contains the following lines
#!/bin/ksh

a= `cat mydate.txt`
echo $a

----
When I run the sample.sh at the command line, it produces an error :
sample.sh[3]: 20040714: not found.


mydate.txt contains only 20040714.
I was trying to transfer the value of the text file to a variable and I want it to display at the screen. It seems that tilde was not recognize.... but other scripts uses tilde and it works fine. Can you give me an idea why this simple unix script does not work using tilde...

Any help will do..

Me-an
Reply With Quote
  #2 (permalink)  
Old 07-14-04, 07:07
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
It's a space that's causing your problem.

A variable assignation followed by a command sets that variable ONLY within the scope of that command.

e.g.

var=gubbins aScript; echo $var

The above would set var to "gubbins" within the context of aScript. The subsequent echoing of $var would output an empty string as var would remain unset in the current shell.

What you are trying to do is set 'a' to an empty string within the context of the command derived from the output of mydate.txt.

i.e.

a= `cat mydate.txt`

is the same as...

a= 20040714

...and seen as there is no such command as 20040714 you get the error.

In short, what you really mean is...

a=`cat mydate.txt`

Incidentally, seen as you are only talking about a single line, you could also write this as...

read a < mydate.txt
Reply With Quote
  #3 (permalink)  
Old 07-14-04, 09:00
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
...and ` is a backtick not a tilde ~

:-)
Reply With Quote
  #4 (permalink)  
Old 07-14-04, 23:01
mean2229 mean2229 is offline
Registered User
 
Join Date: Dec 2003
Location: San Mateo, Rizal, Philippines
Posts: 18
Thumbs up Thanks.

Thanks Damian for the very fast response.

And I also tried removing the space and it works!

Thank you once again..

me-an from Philippines
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On