shell script, why isn't if printing message?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell script, why isn't if printing message?
# 1  
Old 09-24-2009
Question shell script, why isn't if printing message?

Why isn't printing message?
Code:
  1 #!/bin/sh
  2
  3 something(){
  4     echo "Inside something"
  5     echo $1 $2
  6 }
  7 val=$(something "Hello " "world")

But it prints.
Code:
  1 #!/bin/sh
  2
  3 something(){
  4     echo "Inside something"
  5     echo $1 $2
  6 }
  7 val=$(something "Hello " "world")
  8 echo $val


Last edited by cola; 09-25-2009 at 02:58 AM..
# 2  
Old 09-24-2009
I don't see any error's Smilie
Code:
# cat script.sh
#!/bin/sh

something(){
    echo "Inside something"
    echo $1 $2
}
val=$(something "Hello " "world")
echo "$val"

# ./script.sh
Inside something
Hello world

# 3  
Old 09-24-2009
Quote:
Originally Posted by danmero
I don't see any error's Smilie
Code:
# cat script.sh
#!/bin/sh

something(){
    echo "Inside something"
    echo $1 $2
}
val=$(something "Hello " "world")
echo "$val"

# ./script.sh
Inside something
Hello world

Yes there is no error.
But the script bellow doesn't display anything.Why?
Code:
  1 #!/bin/sh
  2
  3 something(){
  4     echo "Inside something"
  5     echo $1 $2
  6 }
  7 val=$(something "Hello " "world")

# 4  
Old 09-25-2009
Why should it? You never tell it to. The echos in your function get captured by $(...), and whatever they printed is saved to val.
# 5  
Old 09-25-2009
Bump.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing line in shell script

Need assistance in getting a shell program . I have csv file and each line has comma separated number. I wanted to take of the comas and print each number in each line . below example. Appreicate your help Row with number ... (14 Replies)
Discussion started by: ajayram_arya
14 Replies

2. Shell Programming and Scripting

Help with printing new line in shell script

I'm having a script which outputs four different attributes A, B, C, D for a list of users. I want to insert expression such that once the output is generated for first user, output for next user should be printed in new line. Please help. (4 Replies)
Discussion started by: surdileep
4 Replies

3. Shell Programming and Scripting

Printing from Shell Script

My print alias that works fine from the command line does not function from withn a shell script. Instead of actually performing the printing, it instead writes out the name of the file I'm trying to print. Does anyone know why? Much Thanks. (3 Replies)
Discussion started by: ttilsch
3 Replies

4. UNIX for Dummies Questions & Answers

Isn't a shell found on a beach? Need help nesting if's or loops.

As of a week ago i thought a shell was somthing found on a beach. I'm a virgin when it comes to scripting and i'm having a really bad time here. What i need to do is prompt for a group number grep the /etc/groups to get the GID and name if it exists i want to prompt the user for... (3 Replies)
Discussion started by: switchkill
3 Replies

5. Shell Programming and Scripting

call a popup message from the shell script

Hi , this is my first querry in this forum and I am new bee to the shell scripting..Please have a glance on my query and give ur valuable suggestions . I have a crown job which performs one function,If the job has done successfully we need to send message to some group as "SUCCESSFUL" or else we... (0 Replies)
Discussion started by: elavv
0 Replies

6. Shell Programming and Scripting

Output in my shell isn't showing properly.

Hi! Can anyone tell me what went wrong in my shell script? for dt_val in `cut -f 1 -d '|' /prod/ods/satyaki/sqlldr/grp.dat` do echo $dt_val done And, the output is - 23 39 (7 Replies)
Discussion started by: satyakide
7 Replies

7. Shell Programming and Scripting

Suppress error message in shell script

Hi All this is a simple script #! /bin/bash FileCnt=`ls -lrt $DIR/* | wc -l` echo $FileCnt how could i escape the error msg if there are no files in $DIR ls: /home/sayantan/test/files/cnt/*: No such file or directory 0 Looking forward for a quick reply Regards, Newbie... (3 Replies)
Discussion started by: newbie07
3 Replies

8. Shell Programming and Scripting

Error message while executing the shell script

Hi All, When I am trying to execute the below shell script I got this error message. script ========== #!/bin/bash /usr/java/jdk1.5.0_10/bin/java - classpath /var/lib/asterisk/agi-bin/mysql-connector-java-3.0.15-ga-bin.jar/: /var/lib/asterisk/agi-bin/jarfiles:... (4 Replies)
Discussion started by: ajayyaduwanshi
4 Replies

9. Shell Programming and Scripting

printing last argument in shell script

All, I am having a shell script and i will pass different argument diferent time . Please tell me how can i find the last argument that i passsed each time when i exec the script. Thanks, Arun. (5 Replies)
Discussion started by: arunkumar_mca
5 Replies
Login or Register to Ask a Question