Defined Command in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Defined Command in UNIX
# 1  
Old 01-29-2013
Defined Command in UNIX

Hello All, I have a question in Unix

Let's say when the command is executed in Unix, where the shell search for that command in Unix. I mean where
that command is defined in Unix.

And how Can we make our own command.
# 2  
Old 01-29-2013
Code:
echo $PATH

Please consult your shell's manual page for further information.
# 3  
Old 01-29-2013
when the command is executed from your console, it looks whether the command is there in your $PATH location.

Code:
 
echo $PATH

to know, where the ls command is there.. execute which ls
# 4  
Old 01-29-2013
Based on the distribution you are using the executable for the command may be stored in some of the common directories like /usr/sbin. You can execute command

Code:
 which <command>

or
Code:
 whereis <command>

to know the source directory of the command executable.

When you execute a command, it is searched across the directories exported in PATH variable. Perform
Code:
echo $PATH

to know the list of directories exported.

If the executable is not found in any of the directories listed, then you will get an error stating command not found.
# 5  
Old 01-29-2013
How Can we make our own command and use?
# 6  
Old 01-29-2013
Create a shell script, and place in one of the directories referred to in your $PATH variable. Or, place in a custom location, and update $PATH appropriately:

Code:
# vi /path/to/shellscript.sh
# chmod +x /path/to/shellscript.sh
# export $PATH=/path/to:$PATH
# which shellscript.sh
/path/to/shellscript.sh
# shellscript.sh
...

Keeping your custom scripts/commands/executables in an appropriate location (normally /usr/local/bin, or ~/bin) will prevent them from becoming mixed with system provided files, and should prevent them being touched during upgrades/etc.

I'd always recommend placing your custom directories at the front of $PATH, so you can override system-provided scripts/binaries if required (with your own wrappers, for example).

Cheers,
ZB
# 7  
Old 02-04-2013
Hello All,
How to run the scripts automatically when the user log into the shell
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX command to copy files from Windows to UNIX box

Hi Folks, I have a file name abc.xml in my windows machine at the location c:\ytr\abc.xml which I want to place at the unix box machine inside cde directory.. at the following location that is /opt/app/cde/ now the credentials of unix box are abc345 -->(dummyid) ftyiu88--->(dummy passwd) ... (4 Replies)
Discussion started by: punpun66
4 Replies

2. Shell Programming and Scripting

Specify an entire UNIX command as a command line argument

I'm trying to write a bash script called YN that looks like the following YN "Specify a question" "doThis" "doThat" where "doThis" will be executed if the answer is "y", otherwise "doThat". For example YN "Do you want to list the file dog?" "ls -al dog" "" Here's my attempt... (3 Replies)
Discussion started by: LeoKSimon
3 Replies

3. AIX

Harddisk1 => Defined

I have an IBM 9110-51A p Series Server with AIX 5.3. It has 2 scsi hard disks hdisk0 and hdisk1 (and 4 on disk array). hdisk1 for few days ago is "Defined". When hdisk1 began "defined" i have a new one unknown disk "available" which called hdisk6. The left led of the case of hdisk1 on the... (4 Replies)
Discussion started by: stetsip
4 Replies

4. Web Development

Invalid command 'Order', perhaps misspelled or defined by a module not included in the server config

I have Apache v2.0.63 on Solaris 10 (x86 on VM). While starting the apache server, facing the following exception - Invalid command 'Order', perhaps misspelled or defined by a module not included in the server configuration Googling says to add the entry LoadModule authz_host_module... (0 Replies)
Discussion started by: poga
0 Replies

5. UNIX Desktop Questions & Answers

Can Unix access Windows' File through Command Prompt in Unix

Hi all, I wish to know whether Unix can access window's file in Unix's terminal? Apart from that, how to copy files or share files between Window and Unix? I get to know of secure copy, however, my company's Unix does not support the feature of secure copy? Any other method for me to share/... (5 Replies)
Discussion started by: jessy83
5 Replies

6. UNIX for Advanced & Expert Users

unix command : how to insert text at the cursor location via command line?

Hi, Well my title isn't very clear I think. So to understand my goal: I have a script "test1" #!/bin/bash xvkbd -text blabla with xbindkeys, I bind F5 key in order it runs my test1 script So when I press F5, test1 runs. I'm under Emacs/Vi and I press F5 in order to have "blabla" be... (0 Replies)
Discussion started by: xib.be
0 Replies

7. Shell Programming and Scripting

Ramdisk already defined

I am trying to mount the ramdisk for sorting, and i get the message "ramdisk already defined." What exactly is /dev/ramdisk0 and is it safe to remove it? # command sudo -S mktd 60 <<EOF initiate EOF # block of code for mktd ... && { print "ramdisk already defined." ... (1 Reply)
Discussion started by: ChicagoBlues
1 Replies

8. Shell Programming and Scripting

assign a command line argument and a unix command to awk variables

Hi , I have a piece of code ...wherein I need to assign the following ... 1) A command line argument to a variable e.g origCount=ARGV 2) A unix command to a variable e.g result=`wc -l testFile.txt` in my awk shell script When I do this : print "origCount" origCount --> I get the... (0 Replies)
Discussion started by: sweta_doshi
0 Replies

9. HP-UX

How to use more than one MPE command STREAM with Unix command in a single shell?

Hello, I have problem in writing the shell script involving MPE command STREAM related to HP-UX and Unix command. Script is sh "nlshCMD 'STREAM <job name1>' | 'SHOWJOB' | grep $HPJOBNUM" sh "nlshCMD 'STREAM <job name2>' | 'SHOWJOB' | grep $HPJOBNUM" sh "nlshCMD 'STREAM <job name3>' |... (1 Reply)
Discussion started by: bosskr
1 Replies

10. Shell Programming and Scripting

How to use more than one MPE command STREAM with Unix command in a single shell?

Hello, I have problem in writing the shell script involving MPE command STREAM related to HP-UX and Unix command. Script is sh "nlshCMD 'STREAM <job name1>' | 'SHOWJOB' | grep $HPJOBNUM" sh "nlshCMD 'STREAM <job name2>' | 'SHOWJOB' | grep $HPJOBNUM" sh "nlshCMD 'STREAM <job name3>' |... (0 Replies)
Discussion started by: bosskr
0 Replies
Login or Register to Ask a Question