Sponsored Content
Top Forums Shell Programming and Scripting Creating a command on a BASH shell Post 302341581 by zaxxon on Thursday 6th of August 2009 07:45:37 AM
Old 08-06-2009
From man bash on my Debian box Smilie
Code:
       [ function ] name () compound-command [redirection]
              This defines a function named name.  The reserved word function is optional.  If the function reserved word is supplied, the parentheses
              are optional.  The body of the function is the compound command compound-command (see Compound Commands above).  That command is usually
              a  list of commands between { and }, but may be any command listed under Compound Commands above.  compound-command is executed whenever
              name is specified as the name of a simple command.  Any redirections (see REDIRECTION below) specified when a function  is  defined  are
              performed  when  the  function is executed.  The exit status of a function definition is zero unless a syntax error occurs or a readonly
              function with the same name already exists.  When executed, the exit status of a function is the exit status of the  last  command  exe-
              cuted in the body.  (See FUNCTIONS below.)

Tbh, I usually write them even without "function" in front of them.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

creating file of 1MB using shell command?

Hi everybody in the forum, I want to create an empty file of say some 1MB ,i mean at the command line itself.How is this possible??????EEK! (4 Replies)
Discussion started by: vijaya2006
4 Replies

2. Shell Programming and Scripting

Using variable with cp command in bash shell

Hi, I am trying to write script to copy some files(/ppscdr/cdrp2p/temp/) from one directory to another directory using shell script. see the script below, #!/bin/sh -f dir_name=20061105 mkdir ${dir_name} cd /ppscdr/cdrp2p/temp pwd cp p2p${dir_name}*.*... (4 Replies)
Discussion started by: maheshsri
4 Replies

3. Shell Programming and Scripting

Creating a command history feature in a simple UNIX shell using C

I'm trying to write a history feature to a very simple UNIX shell that will list the last 10 commands used when control-c is pressed. A user can then run a previous command by typing r x, where x is the first letter of the command. I'm having quite a bit of trouble figuring out what I need to do, I... (2 Replies)
Discussion started by: -=Cn=-
2 Replies

4. Shell Programming and Scripting

Bash shell: Creating Preferences

In OS X I'm currently writing a bash script that requires writing to preference file. I may eventually want to share it with users on other Unix-like OSs and would like to accommodate for that possibility ahead of time. Most OS X applications save preferences in xml-format plist files. These... (4 Replies)
Discussion started by: airsmurf
4 Replies

5. UNIX for Dummies Questions & Answers

more command does not work in bash shell

is there a different command to display contents of a file on the output in bash shell? i tried more and it does not work. (7 Replies)
Discussion started by: npatwardhan
7 Replies

6. UNIX for Dummies Questions & Answers

unix command - bash shell

Hey all, I need to know how many lines of C code are in a source bundle. I have extracted the bundle and hence there is a big directory tree with C files everywhere. So far I have something like: find . -name "*.c" | grep \ ./*/*/*/*/*/* obviously wrong, if someone could help me out... (3 Replies)
Discussion started by: zigga15
3 Replies

7. Shell Programming and Scripting

help needed with creating challenging bash script with creating directories

Hi, Can someone help me with creating a bash shell script. I need to create a script that gets a positive number n as an argument. The script must create n directories in the current directory with names like map_1, map_2 etcetera. Each directory must be contained within its predecessor. So... (7 Replies)
Discussion started by: I-1
7 Replies

8. Shell Programming and Scripting

creating own command interpreter like bash...??

Hello senior members, I am a fairly newbie here. I just want to ask one question that how can once create one's own command interpreter/ shell like bash in unix/linux. I need to execute basic commands like pipes and i/o. Any help in this matter ?? (3 Replies)
Discussion started by: duma188
3 Replies

9. Programming

Creating a bash based restricted shell

Hello. I need to write a command line interface that can be invoked either directly from the shell (command sub-command arguments), or as a shell that can process sub-commands. i want to use bash auto completion for both scenarios. example: lets say my CLI module is called 'mycli' and there... (5 Replies)
Discussion started by: noamr
5 Replies

10. UNIX for Dummies Questions & Answers

Which of the following command displays your login shell in bash shell?

Options:: A)$shell B)echo $ bash C)echo $ O D)$ O (1 Reply)
Discussion started by: raghugowda
1 Replies
exit(1)                                                            User Commands                                                           exit(1)

NAME
exit, return, goto - shell built-in functions to enable the execution of the shell to advance beyond its sequence of steps SYNOPSIS
sh exit [n] return [n] csh exit [ ( expr )] goto label ksh *exit [n] *return [n] DESCRIPTION
sh exit will cause the calling shell or shell script to exit with the exit status specified by n. If n is omitted the exit status is that of the last command executed (an EOF will also cause the shell to exit.) return causes a function to exit with the return value specified by n. If n is omitted, the return status is that of the last command exe- cuted. csh exit will cause the calling shell or shell script to exit, either with the value of the status variable or with the value specified by the expression expr. The goto built-in uses a specified label as a search string amongst commands. The shell rewinds its input as much as possible and searches for a line of the form label: possibly preceded by space or tab characters. Execution continues after the indicated line. It is an error to jump to a label that occurs between a while or for built-in command and its corresponding end. ksh exit will cause the calling shell or shell script to exit with the exit status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the exit status is that of the last command executed. When exit occurs when executing a trap, the last command refers to the command that executed before the trap was invoked. An end-of-file will also cause the shell to exit except for a shell which has the ignoreeof option (See set below) turned on. return causes a shell function or '.' script to return to the invoking script with the return status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the return status is that of the last command executed. If return is invoked while not in a function or a '.' script, then it is the same as an exit. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
break(1), csh(1), ksh(1), sh(1), attributes(5) SunOS 5.10 15 Apr 1994 exit(1)
All times are GMT -4. The time now is 07:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy