problem writing a simple c shell script

#!/bin/csh
echo hello world

this is what i got in a text file called ss1.
i type "chmod 755 ss1.txt" to make it executable.
then when i type

ss1

or

ss1.txt

it says

"ss1 command not found"

what am i doing wrong?

Do you have the current directory (.) in the path (generally a bad idea)?

If not, you need to say

./ss1.txt

The script is either called ss1.txt (an odd name for a shell script), or ss1. Which is it? It can't be both!

well the file's name is "ss1"
but it is a txt file.

Gotcha :smiley:

Then...

./ss1

ok! that's what i get.

"ss1: Command not found."

Still?

Is csh in /bin?

which csh

Try ls and see what the filename actually is...

ok. the file name is "ss1.txt"
so i type

./ss1.txt

and i get this now.

"./ss1.txt: ./ss1.txt: cannot execute binary file"

But you said the script was called ss1. So what is ss1.txt, and why are you running it?

A slight modification to Corona's request:

ls -l ss1*

it is called ss1 but it is a text file. so i have to type "ss1.txt " to run it.
but i get that binary error

This is (presumably) UNIX or Linux you are using?

If your script is called ss1, you run it as ss1 - regardless of whether it's text or binary.

File extensions in UNIX are notional, not like Windows, with file associations, and all.

You didn't answer the ls -l question!

when i run

ls -l ss1*

i get this:
"ss1.txt"
and im on linux.

Linux doesn't have file extensions as you understand them(or text versus binary files either -- they're all just bytes as far as the OS is concerned.) The ".txt" is part of the filename proper, it won't fill in any sort of extension for you. And what the name is doesn't matter one bit -- you could make it ".exe", ".sh", ".omgwtfbbq", or leave off the extension entirely and Linux won't care. As long as the file's set executable it will try to run it. When it does so, it checks if the beginning of the file is the magic "#!" that means a script, or an ELF header for compiled programs.

So, "ss1.txt", the whole thing, is the file name.

I'm a bit lost here :smiley:

So, where is your "hello world" script?

Let's start again, because this isn't getting us anywhere :slight_smile:

Show the full output of these commands:

ls -l ss1*
file ss1*
cat ss1*
ls -l ss1*

-rwx------ 1 adr1g09 ad_csug 46 May  5 18:54 ss1.txt

file ss1*

ss1.txt:

cat ss1*

��#!/bin/csh
echo hello

Are you editing these scripts in Notepad or something? There's garbage before the #!/bin/csh that's preventing it from working, I suspect it's a Unicode byte-order indicator inserted by a Windows program. Try running 'nano ss1.txt' in the shell to get a proper editor inside Linux.

[edit] In fact, delete the file and create a whole new one with nano. You'll probably have problems with carriage returns until you make a new file.

Great :slight_smile: (see the Corona reply)

If this question is related to this post:

http://www.unix.com/shell-programming-scripting/135768-output-problem.html\#post302418817

it is a homework question IMHO.

yeah im writing them in notepad. what should i use?
and i tried nano ss1.txt
i removed the garbage, saved the file, and now it runs, but
"echo hello" does not execute

Agreed. Closed.