LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-19-2009, 09:08 AM   #1
fuske
LQ Newbie
 
Registered: Jun 2004
Location: Sweden
Distribution: slackware
Posts: 8

Rep: Reputation: 0
Script issue with "Undefined variable"


Hi!

I wrote a simple script that's get a variable by input.
I can run it fine by using sh script.

The problem i having is that when i try to execute it with ./script i get:

lala: Undefined variable.
datum=: Command not found.


The script:

#!/bin/csh -f
#
echo write something:
read lala

datum=`grep $lala /var/log/changelog | tail -1 | awk '{print $2 " " $3 " " $4 " " $5}'`

echo Datum......: $datum


I understand that sh make the script execute in a child environment or something like that.
But how do i make this script executable by ./?
 
Old 05-19-2009, 09:15 AM   #2
kellinwood
Member
 
Registered: Jan 2006
Location: Culver City, California
Distribution: Fedora
Posts: 64

Rep: Reputation: 21
Change the first line in the file to

Code:
#! /bin/sh
The interpreters sh and csh have different syntax.
 
Old 05-19-2009, 09:17 AM   #3
fuske
LQ Newbie
 
Registered: Jun 2004
Location: Sweden
Distribution: slackware
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by kellinwood View Post
Change the first line in the file to

Code:
#! /bin/sh
The interpreters sh and csh have different syntax.

Thanks!
 
Old 05-19-2009, 09:41 AM   #4
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
You really DON'T want to use csh as a programming shell, but I know, "to each his own".

That being said, you aren't even writing the script in csh, you are using sh or bash syntax and then trying to send that to the csh interpreter.

Try this instead:

Code:
#!/bin/bash

echo write something:
read lala

datum=`grep $lala /var/log/changelog | tail -1 | awk '{print $2 " " $3 " " $4 " " $5}'`

echo Datum......: $datum
You will also need to run "chmod +x script" to make it executable.

If you REALLY want to use csh, then you will need to convert your script to use csh syntax (note, there is no "read" command in csh).

HTH

Forrest

Last edited by forrestt; 05-19-2009 at 09:42 AM.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"Multiple definition of" and "undefined reference to" in QT Creator with QJson lib echelon89 Programming 1 05-01-2009 06:48 AM
C++ Issue: "undefined reference" Esoteric Programming 11 05-30-2008 05:12 PM
"Broken" envirnment variable (MANPATH) and "/etc/profile.d" question. ErV Slackware 3 03-20-2007 09:42 AM
avgscan "relocation error" "undefined symbol: __dynamic_cast_2" Monster_user Linux - Software 0 02-22-2006 11:57 AM
Bash Script: Problem running variable command containing "" Paasan Programming 2 01-21-2004 01:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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