Help with - shell oneline function ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with - shell oneline function ?
# 1  
Old 04-19-2013
Help with - shell oneline function ?

Experts,

This is working:
Code:
a () {
date ;}
a

But This is not working:
Code:
a () {;date;};a  
ksh: syntax error: `;' unexpected


Is it possible to write the function in online:

Thanks a lot.
# 2  
Old 04-19-2013
Code:
a(){ date; }

This User Gave Thanks to in2nix4life For This Post:
# 3  
Old 04-19-2013
There should be spacing (space, TAB, newline) after the first curly brace, not a semicolon..
Code:
a(){ date;};a


Last edited by Scrutinizer; 04-19-2013 at 04:44 PM..
This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 04-19-2013
Drop the leading semicolon, make sure the { and } are embedded in spaces, and it will fly:
Code:
$ a () { date; } ;a

This User Gave Thanks to RudiC For This Post:
# 5  
Old 04-19-2013
Note the spaces...

Code:
Last login: Fri Apr 19 20:26:12 on ttys000
Barrys-MacBook-Pro:~ barrywalker$ a() { date ; } ; a
Fri 19 Apr 2013 20:27:30 BST
Barrys-MacBook-Pro:~ barrywalker$

This User Gave Thanks to wisecracker For This Post:
# 6  
Old 04-19-2013
Quote:
Originally Posted by RudiC
Drop the leading semicolon, make sure the { and } are embedded in spaces.. [..]
Quote:
Originally Posted by wisecracker
Note the spaces... [..]
Space is only required behind the first curly brace..
These 2 Users Gave Thanks to Scrutinizer For This Post:
# 7  
Old 04-19-2013
Great .. All works. It is simple now to me.

Wonderful. Thanks a lot all.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting shell to Perl I run into shell built in function trap and need alternative in Perl

I am working on converting shell to Perl script. In shell we have built in function trap Do you know alternative in Perl or actually we don't need it? Thanks for contribution (3 Replies)
Discussion started by: digioleg54
3 Replies

2. Shell Programming and Scripting

How to call a function in Shell..?

#!/bin/bash FUN_ECHO(){ echo $1 } FUN_ECHO "hi how are you ?" This code will work fine. BUT is it possible to make the following to work ? FUN_ECHO "hi how are you ?" FUN_ECHO(){ echo $1 } I know that the code will be executed line by line. But i have a number of... (5 Replies)
Discussion started by: linuxadmin
5 Replies

3. Shell Programming and Scripting

function from shell input

Hi all i have the command called printer which needs a usernmae for example i would run the commnad printer <username> how can i write i quick script in perl that if the username is ab then write "denined" and if it is anything else it will work thanks Adam (1 Reply)
Discussion started by: ab52
1 Replies

4. Red Hat

how to call a particular function from one shell another shell script

please help me in this script shell script :1 *********** >cat file1.sh #!/bin/bash echo "this is first file" function var() { a=10 b=11 } function var_1() { c=12 d=13 (2 Replies)
Discussion started by: ponmuthu
2 Replies

5. Shell Programming and Scripting

Function in Shell script

Legends, Can you please debug, what's wrong with the below code. I am gettng unexpected token error RebuldPF() ( #Changing the directory to data directory where the pf exists. cd /home/sandeep/files #Listing the names of the Pricefiles for rebuilding echo "The following pricefiles will... (6 Replies)
Discussion started by: sdosanjh
6 Replies

6. Shell Programming and Scripting

SHELL SCRIPT Function Calling Another Function Please Help...

This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord but only one record is getting wrote in DB.... Please advise ASAP...:confused: function InsertFtg { FTGSTR="" echo "Saurabh is GREAT $#" let... (2 Replies)
Discussion started by: omkar.sonawane
2 Replies

7. Shell Programming and Scripting

awk function from shell

Hi all. I have a selection of awk functions which I have written and tested in a main awk program. From the command line I use nawk -f function -f main to run main and call my functions from within it. I now wish to use these awk function again but want to call them from inside an awk section of... (1 Reply)
Discussion started by: pxy2d1
1 Replies

8. Shell Programming and Scripting

shell function help

SUN os KSH ERROR_CHK () { ERR_DATA="$ABC" if `echo "$ABC" | egrep 'PLS|ERROR|ORA'` ; then echo "Failed: Can't execute procedure ${PRG_NAME} ERROR found " return 1 else echo "Info : ${PRG_NAME} done" fi } my function fails iwth below message "ERROR: not found" I think i... (0 Replies)
Discussion started by: Amresh Dubey
0 Replies

9. UNIX for Advanced & Expert Users

how to see function in shell

Hi, is there any way we can see user defined functions in a shell? thanks in advance, -Ashish (2 Replies)
Discussion started by: shriashishpatil
2 Replies

10. Shell Programming and Scripting

getting the value of a c function in shell script

Let say there is a module fileselection module written in c language which returns the file name. Is it possible to get the file name from the file selection module directly, I mean can we call a c function directly in shell script without doing executable. If possible then how it can be... (1 Reply)
Discussion started by: surjyap
1 Replies
Login or Register to Ask a Question