Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8324371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:02:43+00:00 2026-06-09T00:02:43+00:00

I am new to shell scripts, I am trying to create a simple function

  • 0

I am new to shell scripts, I am trying to create a simple function which will return the concatenated two strings that are passed as parameters. I tried with below code

   function getConcatenatedString() {
       echo "String1 $1"
       echo "String2 $2"
       str=$1/$2
       echo "Concatenated String ${str}"
       echo "${str}"
   }

//I am calling the above function

  constr=$(getConcatenatedString "hello" "world")
  echo "printing result"
  echo "${constr}"
  echo "exit"

I see the below output when running the script with above code,

   printing result
   String1 hello
   String2 world
   Concatenated String hello/world
   hello/world
   exit

If you look at the code I am first calling the function and then I am echoing “printing result” statement, but the result is first comes the “printing result” and echos the statement inside the function. Is the below statement calling the function

   constr=$(getConcatenatedString "hello" "world")

or

   echo ${constr}

is calling the function ?

Because if I comment out #echo ${constr} then nothing is getting echoed !!! Please clarify me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:02:45+00:00Added an answer on June 9, 2026 at 12:02 am

    The first is calling the function and storing all of the output (four echo statements) into $constr.

    Then, after return, you echo the preamble printing result, $constr (consisting of four lines) and the exit message.

    That’s how $() works, it captures the entire standard output from the enclosed command.

    It sounds like you want to see some of the echo statements on the console rather than capturing them with the $(). I think you should just be able to send them to standard error for that:

    echo "String1 $1" >&2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a new launchagent file that will execute a shell script
I'm new to shell,I just learned that use (command) will create a new subshell
I am trying to make a new command which runs a shell script that
I'm trying to set up a shell script that will start a screen session
Here's the basic setup. I'm trying to create a simple middleware component that would
I'm trying to write a shell script that, when run, will set some environment
I'm trying to create a script that will automatically backup a complete directory tree.
I'm trying to create an RPM in Fedora 15 that will install my software,
I have a simple webpage deployed to tomcat which runs certain shell scripts based
So, I'm new to shell scripts and I'm really doing this as a learning

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.