LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 11-27-2006, 12:36 PM   #1
maheshdf
LQ Newbie
 
Registered: Nov 2006
Posts: 10

Rep: Reputation: 0
Unhappy Running shell script on Fedora core


Hello Friends,

I have installed Fedora core 6 and tring to run some shell scripts but it didn't give any result. I am confused !!!

Here is my test script,

set var = net
echo $var

After I run the script it didn't show any output.

defauslt shell for the login is tcsh and .zshrc file as follows,


#
# .zshrc is sourced in interactive shells.
# It should contain commands to set up aliases,
# functions, options, key bindings, etc.
#

autoload -U compinit
compinit

#allow tab completion in the middle of a word
setopt COMPLETE_IN_WORD

## keep background processes at full speed
#setopt NOBGNICE
## restart running processes on exit
#setopt HUP

## history
#setopt APPEND_HISTORY
## for sharing history between zsh processes
#setopt INC_APPEND_HISTORY
#setopt SHARE_HISTORY

## never ever beep ever
#setopt NO_BEEP

## automatically decide when to page a list of completions
#LISTMAX=0

## disable mail checking
#MAILCHECK=0

# autoload -U colors
#colors

Any body have any idea about this ?

Mahesh
 
Old 11-27-2006, 01:22 PM   #2
fordeck
Member
 
Registered: Oct 2006
Location: Utah
Posts: 520

Rep: Reputation: 61
Try:

Code:
#!/bin/bash
VAR=something
echo $VAR
You would need to make your script executable such as:

Code:
chmod 755 <scriptname>

Last edited by fordeck; 11-27-2006 at 05:39 PM.
 
Old 11-27-2006, 01:27 PM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Please paste code extracts in [code] tags (in the advanced mode of the forums post editor, you can just highlight the text and click the # button). It makes it a lot easier to read won't wrap lines confusingly like non-code tags does.

.zshrc is not touched by tcsh, so that can safely be ignored. See the FILES section of the tcsh manpage for a full list of files which tcsh uses.

Please post the full contents of the script file, and do ls -l on it, and show how you are executing it, e.g. if the script file is called "test.sh", do this and post the results here (inside [code] tags!):
Code:
chubby:~/tmp> ls -l test.sh
-rwxr-xr-x 1 matthew matthew 66 2006-11-27 18:26 test.sh
chubby:~/tmp> ./test.sh
my var variable contains: net
chubby:~/tmp> cat test.sh
#!/bin/tcsh

set var = net
echo "my var variable contains: $var"
and yes, my machine is named "chubby".
 
Old 11-27-2006, 04:39 PM   #4
maheshdf
LQ Newbie
 
Registered: Nov 2006
Posts: 10

Original Poster
Rep: Reputation: 0
Ok I created the .cshrc see below, but still I cat see any result out put.

Code:
#
#  -----  Aliases  -----  #

   alias h      history
   alias rm    "rm i"

   alias dir   "ls -al | more"
   alias md    mkdir
   alias rd    rmdir

   alias vt100 "set term=vt100"
   alias wy60  "set term=wyse60"
#
#  -----  Environment Control  -----
#
   mesg y    # let other users write messages to my screen
   notify -y         # inform me when mail arrives
   set history = 50  # remember the last 50 commands
   set path = ( /usr/bin /bin /usr/ucb/bin /usr/local/bin . )
#
scrip file as follows,

Code:
[ppscdr@cdrwebserver ~]$ more dircreater.sh
#!/bin/tcsh
set d=test1
echo ${d}
mkdir ${d}
[ppscdr@cdrwebserver ~]$ ls -al dircreater.sh
-rwxr-xr-x 1 ppscdr users 46 Nov 27 23:32 dircreater.sh
[ppscdr@cdrwebserver ~]$
Kindly tell me what is wrong?

Thanks
 
Old 11-27-2006, 05:08 PM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Show me how you are executing it, and what the output is. After running it, do this too:
Code:
ls -l test1
 
Old 11-27-2006, 05:33 PM   #6
maheshdf
LQ Newbie
 
Registered: Nov 2006
Posts: 10

Original Poster
Rep: Reputation: 0
Here is the output,

Code:
[ppscdr@cdrwebserver ~]$ sh dircreater.sh

mkdir: missing operand
Try `mkdir --help' for more information.
[ppscdr@cdrwebserver ~]$ ls -l test1
ls: test1: No such file or directory
[ppscdr@cdrwebserver ~]$

Last edited by maheshdf; 11-27-2006 at 05:34 PM.
 
Old 11-27-2006, 05:57 PM   #7
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Don't run it like this. What you're doing is telling the borne shell, sh, to process the file, which is written with the csh syntax. It's something like telling a python interpreter to run a perl program.

You could execute in one of the following ways:
  1. ./dircreater.sh
  2. tcsh dircreater.sh
 
Old 11-27-2006, 06:32 PM   #8
maheshdf
LQ Newbie
 
Registered: Nov 2006
Posts: 10

Original Poster
Rep: Reputation: 0
Ok. I understod, but why it dosen't show the echo out put.
 
Old 11-27-2006, 06:44 PM   #9
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Quote:
Originally Posted by maheshdf
Ok. I understod, but why it dosen't show the echo out put.
Because in borne-style shells, the command set doesn't set the value of variables like it does in tcsh. It is used to set special shell modes. In borne style shells, the variable assignment syntax is like this:
Code:
variablename=value
By the way, the csh and similar shells are generally not considered very good for scripting. My advice would be to switch to bash for both interactive and programming use. I recommend a switch for interactive use as well as scripts because once you've learned the syntax, it's easy to knock up one-liner scripts on the command line and do a lot of work without having to touch a script file.

Last edited by matthewg42; 11-27-2006 at 06:47 PM.
 
Old 11-29-2006, 04:50 AM   #10
maheshdf
LQ Newbie
 
Registered: Nov 2006
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks for the help.
 
  


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
Running shell script within a C or C++ program Quantum0726 Programming 2 06-15-2005 10:14 PM
running a program from shell script Suinatsa Programming 10 04-14-2005 12:25 PM
running SHell script from java anirudh Programming 2 01-07-2005 08:37 AM
Running shell script install, how? henrikanttonen Linux - Newbie 9 08-06-2004 09:46 PM
c/c++ running a shell script? thermalpants Programming 3 05-12-2002 12:41 PM


All times are GMT -5. The time now is 02:42 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration