Function return string in a shell script - Programming On Unix
Users browsing this thread: 1 Guest(s)
|
|||
Hello,
I'm writing a shell script and I have the following problem: I need to return a value from a function in my shell script. I use sh as shell. So until now I have use echo and everything were fine. I came to the idea to improve my script by displaying what is done in the functions I have written. So I have multiple echo's in my function and the last echo is not the returned value. An Example: Code: #! /bin/sh The script returns Code: This is a try which was expected. Now if I try Code: #! /bin/sh I get Code: This is a try End of function So the echo's are concatenated. I don't know very well what happens, I assume because of the construct $(..) nothing is displayed on the terminal and all echo's are stored in the variable result. Does it work like that ? In my case it's something like Code: function rename(){ It's simplified. But the idea is the same: I have some conditions to rename a file and I want to return the new filename if the file has been renamed. But in the same time I want to display some information on the terminal for the user. What are the options ? Thank you! |
|||
Messages In This Thread |
Function return string in a shell script - by Tristelune - 07-08-2015, 01:22 PM
RE: Function return string in a shell script - by movq - 08-08-2015, 05:06 AM
RE: Function return string in a shell script - by Tristelune - 09-08-2015, 02:52 PM
RE: Function return string in a shell script - by xero - 10-08-2015, 02:57 PM
RE: Function return string in a shell script - by venam - 01-09-2020, 06:04 AM
|