howto place in one line output from two functions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting howto place in one line output from two functions
# 1  
Old 06-08-2010
howto place in one line output from two functions

Hi

I would like to place in one line output from two functions. Both functions return text with print cmd.

When I place above code in script it will place them in series.
e.g.
Code:
     1  #/bin/ksh
     2
     3  function1()
     4  {
     5          print "My name is"
     6          print "His name is"
     7
     8  }
     9
    10  function2()
    11  {
    12          print "Norbert Jakubczak"
    13
    14  }
    15
    16
    17  function1;function2

Moderator's Comments:
Mod Comment Use code tags please, ty.

Last edited by zaxxon; 06-08-2010 at 04:26 AM.. Reason: code tags
# 2  
Old 06-08-2010
You are missing a ! in the 1st line. Use echo, not print. print is for a different purpose in this case (check man print if you want to know).

A possible way:
Code:
$> cat mach.ksh
#!/usr/bin/ksh

function1()
{
        echo one
        echo two
}

function2()
{
        echo three
}

printf "%s\n" "`(function1; function2)| tr -s '\n' ' '`"

exit 0
$> ./mach.ksh
one two three



---------- Post updated at 09:38 AM ---------- Previous update was at 09:33 AM ----------

or without tr:

Code:
$> cat mach.ksh
#!/usr/bin/ksh

function1()
{
        echo one
        echo two
}

function2()
{
        echo three
}

VAR=`(function1; function2)`
echo $VAR

exit 0
$> ./mach.ksh
one two three

# 3  
Old 06-08-2010
Depending on OP's need this should also work:

Code:
function1()
{
        VAR+="one "
        VAR+="two "
}

function2()
{
        VAR+="three"
}

function1; function2;echo $VAR

# 4  
Old 06-08-2010
Code:
{ function1;function2;}|xargs

or
Code:
echo $(function1;function2)

Code:
cat <<<$(function1;function2)


Last edited by Scrutinizer; 06-08-2010 at 06:15 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Remove new line for a particular place

Hello All, I have a text file which gets uploaded to tables using shells script. However before running that script I need to alter it, like in the below I have to firstly find the word 1234 and remove the new line from end of it. 1234,5678,fasfasasfsadf abc changes to... (11 Replies)
Discussion started by: Sandeep_sandy
11 Replies

2. Shell Programming and Scripting

How to execute functions or initiate functions as command line parameters for below requirement?

I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line if then... (8 Replies)
Discussion started by: saku
8 Replies

3. Shell Programming and Scripting

useless line feeds in ldapsearch output. Howto remove with shell script?

Hi $ cat ad.sh ldapsearorg -x -LLL -h sb1131z.testbadbigcorp.org -D "CN=ADMINZZ,OU=AdminRoles,DC=testbadbigcorp,DC=org" -w "UT3w4f57lll--4...4" -b "OU=Test,DC=testbadbigcorp,DC=org" "(&(&(&(&(objectCategory=person)(objectClass=user)(lockoutTime:1.2.840.113556.1.4.804:=4294967295)))))" dn$... (3 Replies)
Discussion started by: slashdotweenie
3 Replies

4. Shell Programming and Scripting

How to enumerate mounted disks and place output in array ?

Hi. I'm new to scripting / programming and was wondering what the best way to output all mounted storage devices and their names to an array would be ? I would like to achieve this using the bash shell. Any assistance with this would be greatly appreciated. Regards, Jonno :b: (4 Replies)
Discussion started by: Jonno888
4 Replies

5. Shell Programming and Scripting

howto add line as a first line into a non empty file

Hi Trying to do like this : echo "$variable1\n $(cat file.txt)" but it only adds one time. When I run this cmd again with different variable it only replaces line of variable1. How to add constantly line into first line in file ? (3 Replies)
Discussion started by: presul
3 Replies

6. Shell Programming and Scripting

Howto return the single penultimate line from my output

Hi All I have what seems to be something quite trivial but for the life of me can't work out a solution. Basically, I have the following script that reads a version report that contains certain flags. If a condition is true, I want to print the value of column 2, sort them uniquely and return... (2 Replies)
Discussion started by: kingpin2502
2 Replies

7. UNIX for Dummies Questions & Answers

howto replace field in line

Hi all, I'm writing a script in bash where i'm reading line by line into variable, and the i want to replace the second filed in the line with another number, for example if the line looks like this: 10 20 30 40 50 it should look like this: 10 90 30 40 50 and put the new result inside... (1 Reply)
Discussion started by: morfix
1 Replies

8. UNIX for Dummies Questions & Answers

HOWTO Append String to End of Line

I have a comma delimited text file and need to appened ",000000" to the end of every line. For example: Before: "D700000","2006" ,"5000","Open Year" ,"Conversion" ,"Wk64","Productive Payroll $" ,1103.45 After: "D700000","2006" ,"5000","Open Year" ,"Conversion" ,"Wk64","Productive Payroll... (3 Replies)
Discussion started by: bggibson
3 Replies

9. Shell Programming and Scripting

Getting the value of a line, that changes place

Hi I am trying to get the value of several results in a file called seq032.diag. The values I am looking for is down under Smooth Tracking nodes and is for g01r01 g02r01 s01t02 etc etc. The problem is that when I try to use look for text and tail etc, it works fine in one result file. In... (1 Reply)
Discussion started by: Navigatorchief
1 Replies

10. Shell Programming and Scripting

How to place the output of two different echo statements on one line

Hello there, I wrote a shell script to modify the code for some of our clients in our client database. Before starting the data modification the program performs a few checks. When a check is being performed, it should be shown on the screen of the user running the program, the result of... (5 Replies)
Discussion started by: JoBa
5 Replies
Login or Register to Ask a Question