LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Running shell script on Fedora core (https://www.linuxquestions.org/questions/linux-newbie-8/running-shell-script-on-fedora-core-505266/)

maheshdf 11-27-2006 11:36 AM

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

fordeck 11-27-2006 12:22 PM

Try:

Code:

#!/bin/bash
VAR=something
echo $VAR

You would need to make your script executable such as:

Code:

chmod 755 <scriptname>

matthewg42 11-27-2006 12:27 PM

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".

maheshdf 11-27-2006 03:39 PM

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

matthewg42 11-27-2006 04:08 PM

Show me how you are executing it, and what the output is. After running it, do this too:
Code:

ls -l test1

maheshdf 11-27-2006 04:33 PM

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 ~]$


matthewg42 11-27-2006 04:57 PM

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

maheshdf 11-27-2006 05:32 PM

Ok. I understod, but why it dosen't show the echo out put.

matthewg42 11-27-2006 05:44 PM

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.

maheshdf 11-29-2006 03:50 AM

Thanks for the help.
:)


All times are GMT -5. The time now is 04:21 AM.