473,473 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to use a shell script as a linux command

17 New Member
Hai ,

I have a shell script in my directory
filename = c
-----
#/bin/bash
clear
-----
root>c
if i run this script in my directory it is working
but i have this one to use like linux command
whereever i am giving c that terminal or console has to be clear
please help me
Apr 25 '07 #1
2 2486
sicarie
4,677 Recognized Expert Moderator Specialist
Hai ,

I have a shell script in my directory
filename = c
-----
#/bin/bash
clear
-----
root>c
if i run this script in my directory it is working
but i have this one to use like linux command
whereever i am giving c that terminal or console has to be clear
please help me
Try this:

# ./c

That is a way to execute programs when the directory is not in your path (if it is, you should be able to execute by just typing the name).

I think (though please someone correct me if I'm wrong) that you can use
# echo $PATH
to see what your current path is set at, and I can't remember of the top of my head, but if you Google "add to path" and the OS flavor you're using, you'll see pretty quickly how to edit the path.
Apr 25 '07 #2
prn
254 Recognized Expert Contributor
kalaisuresh appears to be using bash as his shell, so:

$ echo $PATH

should work fine to show the path. Let's suppose the result looks like this:

Expand|Select|Wrap|Line Numbers
  1. [prn@deimos ~]$ echo $PATH
  2. /usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin
  3.  
A sensible thing to do (and commonly done) would be to create a "bin" directory for storing personal programs. If so, I might create a directory as /home/prn/bin and put a program, e.g., like his c into that directory. Now I want to make sure that when I type "c[enter]" at my prompt, that my program c is the one that is executed. (In this example, there probably isn't a system equivalent, but just to be sure, it would be wise to check. Use the command
which c
to see if the system would find another program of the same name on your PATH).

Now you you want to make sure that your system will always find your program c for you. Edit your .bash_profile and, toward the end, include a line like:
PATH=$HOME/bin:$PATH
this puts the directory /home/bin/prn (after all, this is my example and I know what my login is -- I'm less sure about yours :)) at the beginning of my path. Whatever your login name is, it will put YOUR bin directory, i.e., the one hanging off your $HOME at the beginning of your path.

Now, after
Expand|Select|Wrap|Line Numbers
  1. . .bash_profile
(to rerun your profile script):
Expand|Select|Wrap|Line Numbers
  1. [prn@deimos ~]$ echo $PATH
  2. /home/prn/bin:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin
  3.  
/home/prn/bin is now the first place my shell will look for programs.

Of course, in the case of something so simple, it would probably be a lot easier to put a line like
Expand|Select|Wrap|Line Numbers
  1. alias c='clear'
into your .bashrc file.

There is one additional comment I feel almost compelled to make and that involves the line
root>c
from the original post. I hope that doesn't mean what I think it does. It's a really good idea NOT to be root all the time. Make sure you have a normal user account and generally use that. If you're not sure why, that's probably a good topic for another thread.

Best of Luck,
Paul
May 3 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: melih.onvural | last post by:
Group, I want to get into a remote server, tail a file, and see if the last line is an error or not. I think that I've figured out how to shell over and tail the file. I have the specific server...
4
by: Yann.K | last post by:
Hello. Using Tkinter, i would create a widget which display a shell command return. This return is long, and i would display a real time display (like with the tail -f commande on Linux) I...
4
by: mailar | last post by:
Hi, I am trying to register my UDF named 'myUDF.sql" (which has @ as its command terminating character) with sample database I am able to do so through the Linux shell prompt using the following...
1
by: Siebbel | last post by:
Hello, I posted this problem already in the linux section but without positive result. Perhaps someone here has experienced the smae problem. I am pretty new with writing shell scripts and...
1
by: jaywelbourn | last post by:
Hi, I'm trying to use a .net windows application within linux, using WINE, to run a shell script. The reason is that I need to use linux's dd command on a ext2 filesystem that's on an external...
1
by: Svenn Are Bjerkem | last post by:
Hi, as a user on a linux system I am member of the groups "users" and "design" with users as my default group. To controll the accessibility of some parts of the file system, creation of files and...
1
by: raocheng | last post by:
Please see the following code. Suppose I have many shell commands to be executed. And I don't want to fork a sub shell for each command(eg: status,output = commands.getstatusoutput(cmd)) because...
5
by: inetquestion | last post by:
I am looking for a web interface for shell commands or shell scripts. Does anyone know of any exexisting php scripts which would solve this requirement? PHP form accepts input from a user, then...
3
by: mmm | last post by:
I am looking for advice on Python Editors and IDEs I have read other posts and threads on the subject and my two questions at this time are mainly about the IDLE-like F5-run facilities. While I...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.