• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

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.
0
qiang8
Asked:
qiang8
  • 2
  • 2
1 Solution
 
mpassCommented:
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.
0
 
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 ####

error:
myfile:command not found

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


 
0
 
lutadorCommented:
Please login and provide the output to the following commands:

1. ls -ln /bin/myfile
2. grep $USER /etc/passwd
3. echo $PATH
0
 
mpassCommented:
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:

#!/bin/tcsh
or for csh
#!/bin/csh

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

#!/bin/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.



0
 
qiang8Author Commented:
Thank you very much for ur help ... it works
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now