Find the answer to your Linux question:
Results 1 to 8 of 8
I have a small c-shell script written for me by a friend that I would like to run. When I type at the command prompt in a terminal window, “cat ...
  1. #1
    Just Joined!
    Join Date
    Nov 2007
    Location
    Biloxi, MS
    Posts
    4

    TCSH at $prompt returns META_CLASS: Undefined variable.

    I have a small c-shell script written for me by a friend that I would like to run.
    When I type at the command prompt in a terminal window, “cat /etc/shells”, I get the following output:

    /bin/ash
    /bin/bash
    /bin/bsh
    /bin/csh
    /bin/sh
    /bin/tcsh

    From what I've been reading on the internet this tells me what shells are currently installed and available for use. Great! I can see csh and tcsh are available and they are just what I need to run the script.

    I've also learned that it is a simple matter to switch between shells by simply typing at the command prompt the name of the shell. Well, that's easy enough for me to do so.....

    I try it out by typing “ash” and get a new $ prompt that is not prefixed with my user name. Typing “bash” returns my old prompt with user name. Typing “bsh” and “sh” also produce a new $ prompt. I am assuming the command in each instance has been successful and the described shell ash, bsh, or sh are now running. However, when I try to invoke csh or tcsh by typing “csh” or “tcsh” at the command prompt it returns, “META_CLASS: Undefined variable.”

    Drats! The ONE shell I want to use is beyond my reach. Can anyone tell me what's happening here and what to do about it?

    I did see in an article somewhere this sequence: “tcsh -l”
    I tried typing this at the command prompt and got the following:

    META_CLASS: Undefined variable.
    /etc/csh.cshrc: error in /etc/profile.d/10mandriva-release.csh
    META_CLASS: Undefined variable.
    /etc/csh.cshrc: error in /etc/profile.d/10pclinuxos-release.csh
    META_CLASS: Undefined variable.
    /etc/csh.cshrc: error in /etc/profile.d/menustyle.csh

    Something else that is happening is that when I create the simple “hello world” script like so,

    #!/bin/bash
    echo hello world

    give it all the proper permissions to make it -rwxrwxrwx,
    type ./hello, I get this error:

    Exec format error. Binary file not executable.

    I've looked high and low on the internet for answers to these problems but have found no solutions. Can anyone here help me?

    Thank you for your consideration.

    Kevin

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    I don't know tcsh from a hole in the ground, but since the gopher: URL scheme is not particularly active these days, I thought I'd google this:
    Code:
    tcsh META_CLASS
    The fifth entry on the first page yielded this nugget after scrolling down a bit:
    Code:
    There's a file in /etc/profile.d/ called 10pclinuxos-release.csh
    
    Make a copy ;-) and as root, change the line that reads
    
    setenv META_CLASS $META_CLASS
    
    to read
    
    setenv META_CLASS
    
    and save it. It should take affect next time you start a c-shell.
    In your case, I'd also apply that recipe to the other two similarly named files in your error messages.

    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Nov 2007
    Location
    Biloxi, MS
    Posts
    4

    A Magic Wand

    waved over my computer wouldn't have worked any better than the instructions you gave me, Bill. I changed the 10mandriva-release.csh and 10pclinuxos-release.csh as per the instructions. I left the menustyle.csh unchanged, however, because the line in it that began with "setenv" was not followed by "META_CLASS $META_CLASS"

    Testing after the first two were changed appeared to work. Typing "tcsh" at the prompt gives me another prompt that I assume is the C-shell. Is there a command I can type that would tell me for sure what shell I'm in?

    I'm one step closer to my goal........ but still not there yet. Now when I type "./myfilename" that begins with the line "#!/bin/tcsh" I get the same error I've been getting when I try to run the hello world script in bash -- Exec format error. Binary file not executable. I'm trying to learn to write scripts, but I can't even get the simplest one that most tutorials begin with to work yet. I follow all the instructions to the Tee -- I think -- but continue to get this same error.

    Thanks for taking your time to help a lost stranger.

    Kevin

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    I have an idea, but can't flesh it out right now. I'll look at it when I come back from the Four Mile Trail, ok?
    --
    Bill

    Old age and treachery will overcome youth and skill.

  5. #5
    Linux Engineer rcgreen's Avatar
    Join Date
    May 2006
    Location
    the hills
    Posts
    1,114
    Make sure the script starts on the first line, that there is
    no blank line or other invisible bytes preceding the actual
    first line.

  6. #6
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192

    Oh, my aching body.

    Haven't taken the Four Mile Trail for about 2 1/2 years, since I met Susan. She's a wonderful cook, and I've gained 20 pounds. And all these buff twentysomethings took the bus up to the top and walked down. Can you imagine? Young whippersnappers (* grumble grumble *).

    Sorry, moderator, that was off-topic. Now let's roll up our sleeves and get to work. There are two issues here. Let's take the simpler one first:
    Is there a command I can type that would tell me for sure what shell I'm in?
    There are several ways to approach this. I'll show you the two most obvious to me.

    For just about all shells, the expression $$ means "the process number of the process running the shell that's interpreting the $$".

    So try this at the command line:
    Code:
    echo $$
    ps -ef | grep $$ | grep -v grep | grep -v ps
    This can be useful if you're writing a script which needs to know which shell is executing it. Alternatively, you could do this:
    Code:
    head -1 $0
    but what if the script doesn't begin with the #! dance? (That situation came up once when I wanted to construct a file which would work equally well as a script and a C program, producing no syntax errors in either case.)

    Here's something fun to run:
    Code:
    #!/bin/bash
    
    echo === Here\'s /etc/shells:
    
    sed -e 's/^/  /' /etc/shells
    
    for the_shell in $( cat /etc/shells )
    do
    
      echo "#!$the_shell" > scratch
    
      # Single quotes (as opposed to double quotes) are important in the following
      # line.
    
      echo 'ps -ef | grep $$ | grep -v grep | grep -v ps' >> scratch
      echo 'head -1 $0' >> scratch
    
      chmod 700 scratch
    
      echo === When I run:
      sed -e 's/^/  /' scratch
      echo === I get:
      ./scratch | sed -e 's/^/  /'
    done
    I won't make you cut 'n' paste 'n' run. (I wouldn't even think of what that might mean for military strategy.) I'll do it for you. The output on my system is this:
    Code:
    === Here's /etc/shells:
      /bin/bash
      /bin/tcsh
      /bin/csh
      /bin/ash
      /bin/ksh
      /bin/zsh
    === When I run:
      #!/bin/bash
      ps -ef | grep $$ | grep -v grep | grep -v ps
      head -1 $0
    === I get:
      wally    26756 26751  0 23:23 pts/23   00:00:00 /bin/bash ./scratch
      #!/bin/bash
    === When I run:
      #!/bin/tcsh
      ps -ef | grep $$ | grep -v grep | grep -v ps
      head -1 $0
    === I get:
      wally    26765 26751  0 23:23 pts/23   00:00:00 /bin/tcsh ./scratch
      #!/bin/tcsh
    === When I run:
      #!/bin/csh
      ps -ef | grep $$ | grep -v grep | grep -v ps
      head -1 $0
    === I get:
      wally    26774 26751  0 23:23 pts/23   00:00:00 /bin/csh ./scratch
      #!/bin/csh
    === When I run:
      #!/bin/ash
      ps -ef | grep $$ | grep -v grep | grep -v ps
      head -1 $0
    === I get:
      wally    26783 26751  0 23:23 pts/23   00:00:00 /bin/ash ./scratch
      #!/bin/ash
    === When I run:
      #!/bin/ksh
      ps -ef | grep $$ | grep -v grep | grep -v ps
      head -1 $0
    === I get:
      wally    26792 26751  0 23:23 pts/23   00:00:00 /bin/ksh ./scratch
      #!/bin/ksh
    === When I run:
      #!/bin/zsh
      ps -ef | grep $$ | grep -v grep | grep -v ps
      head -1 $0
    === I get:
      wally    26800 26751  0 23:23 pts/23   00:00:00 /bin/zsh ./scratch
      #!/bin/zsh
    There. That will give you enough material to write your own script to output the name of the shell in whatever format you want.

    Ok. (Harrumph.) On to (not onto) the other issue.

    rcgreen was on to something useful (not quite the same as "onto something useful"; consult your English teacher) when (s)he said:
    Make sure the script starts on the first line, that there is
    no blank line or other invisible bytes preceding the actual
    first line.
    That's useful advice, but not all scripters can jump directly from that to a solution. So would you do this, please?
    Code:
    od -t xC name_of_troublesome_script | head
    and post the results in this thread?
    --
    Bill

    Old age and treachery will overcome youth and skill.

  7. #7
    Just Joined!
    Join Date
    Nov 2007
    Location
    Biloxi, MS
    Posts
    4

    Thumbs up We've hit paydirt!

    I got to thinking about rcgreen's suggestion. I had realized that the first line of a script couldn't be blank and although the script file's first line appeared to be the shebang line I thought, “Wait just a minute here. I created the script with Open Office Writer and even though I saved it as a txt file there might be some invisible coding in there.” So, I recreated the file using Kwrite; followed up with chmod 777 hello, ./hello and it WORKS!!! Not only that but the c-shell script my friend had written for me also works pursuant to Bill's instructions yesterday and reconstructing it in Kwrite also. I had typed out the script myself based on instructions he sent me in an email.

    I did go ahead and run the code you gave me, Bill.
    od -t xC name_of_troublesome_script | head

    On the original Office Writer hello txt file it yielded:

    0000000 ef bb bf 23 21 2f 62 69 6e 2f 62 61 73 68 0a 65
    0000020 63 68 6f 20 68 65 6c 6c 6f 20 77 6f 72 6c 64
    0000037

    On the new hello script written with Kwrite it yields this:

    0000000 23 21 2f 62 69 6e 2f 62 61 73 68 0a 65 63 68 6f
    0000020 20 68 65 6c 6c 6f 20 77 6f 72 6c 64
    000003

    ps -ef | grep $$ | grep -v grep | grep -v ps

    works very nicely. I'll be keeping this in the little repository of commands I'm accumulating.

    When I'm in the TCSH shell and type it I get:
    501 10416 10347 0 08:57 pts/1 00:00:00 -csh

    When I'm in the Bash shell and type it I get:
    501 10478 10416 0 08:59 pts/1 00:00:00 bash

    When in the Ash or Bsh shell and type it I get:
    tcsetpgrp failed, errno=1
    tcsetpgrp failed, errno=1
    tcsetpgrp failed, errno=1

    I know this probably means something that isn't good, but I'm not too concerned about it at the moment as I don't anticipate working in those environments.

    When I use the “head -1 $0” alternative you provided, Bill
    I get
    head: cannot open `bash' for reading: No such file or directory
    in Bash

    and
    head: cannot open `tcsh' for reading: No such file or directory
    in TCSH

    But, the first one gives me what I need so I don't suppose it matters.

    Bill, rcgreen. Thank you very much for your help. This was a big issue for me and it is now solved. I can now embark into the world of scripts on my linux operating system. You had mentioned, Bill, that you didn't know TCSH from a hole in the ground. You also don't know me from a hole in the ground. My soul still gasps in awe at the beauty and wonder of human kindness whenever I encounter it in the world, for when I experience it I find myself face to face with the mystery of the All itself.

    Kevin

  8. #8
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    My soul still gasps in awe at the beauty and wonder of human kindness whenever I encounter it in the world, for when I experience it I find myself face to face with the mystery of the All itself.
    Awwwww, you're just saying that 'cause it's true.
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...