Newbie...why can't execute command?

I've created a file "myfile" with the following simple line:

history | tail -10 | more

then, I chmod 750 myfile so that it become exe file. But when try to execute, the following error:

bash: myfile: command not found

Pls advise....thanks.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It looks like the file you created isn't in your path. You should be able to run it by changing to directory the file is in and typing "./myfile" as opposed to "myfile". You can see what's in your current path by typing "echo $PATH". If you want to be able to run this by typing "myfile" either add it to a directory in your path or add the directory it's in to your path environmental variable.

Quick note: You can get the same result for the command above with "history | tail". The default value for tail is 10 lines, so you don't really need to do a "tail -10". Unless you're doing really long commands the "more" isn't really needed since tail will automatically print it's output. Hope this helps.
qiang8Author Commented:
It still can't work.....anywhere thanks for ur prompt reply.

I have included "myfile" directory in the .cshrc file as below but still fail.

set path =(/bin:/usr/bin......)
### where /bin contains myfile ####

myfile:command not found

Pls advise and suggest what other things that I shall do. Any global setting that I might miss out? Thanks.

Please login and provide the output to the following commands:

1. ls -ln /bin/myfile
2. grep $USER /etc/passwd
3. echo $PATH
I should have paid more attention to your original post. You are editing your .cshrc file which is fine, but the error message you get is;

bash: myfile: command not found

The bash at the beginning of the line means you are running the bash shell. You need to change your shell to the csh. Unfortunately, most linux distributions do not contain the csh. They do usually contain the tcsh which is compatible with the older csh. So follow these instrucions, and you should be alright.

cp ~/.cshrc ~/.tcshrc
This will copy your current .cshrc file to a .tcshrc file.

chsh or chgsh
This will prompt you to enter the new shell you want to use. Tell it, "/bin/tcsh" (without the quotes)Most likely, you will have to reboot to get it to read your new shell. Only have to do this once.

echo $SHELL
Use this command to verify what shell you are actually running.

which myfile
This command will search your path and tell you the location of a filename you provide. In this case the filename myfile. If it says command not found, then myfile is not in your path. Otherwise it will give the location of the file. (i.e. /bin/myfile)

For the script to actually work, you must have at least two lines in it. The first line of any script should contain the path of the shell you want it to run under. Using the tcsh it would look like this:

or for csh

So your script should really look like this if you use the tcsh.

history | tail -10 | more

Instead of using a script for this command, you might want to use an alias instead. You can do this by editing the .tcshrc file and adding a line that looks like this:

alias myfile history | tail -10 | more

After editing that file, type "source ~/.tcshrc" to reread your .tcshrc file with the new changes. Now whenever you type myfile the command 'history | tail -10 | more' will be run. I really hope this helps. If not please leave another comment. Thanks.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
qiang8Author Commented:
Thank you very much for ur help ... it works
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.