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 7032419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:56:01+00:00 2026-05-28T00:56:01+00:00

my question is actually rather easy, but I suck at bash scripting and google

  • 0

my question is actually rather easy, but I suck at bash scripting and google was no help either. So here is the problem:
I have an executable that writes me a few variables to stdout. Something like that:

MrFoo:~$ ./someExec 
Variable1=5
Another_Weird_Variable=12
VARIABLENAME=42

What I want to do now is to read in a specific one of these variables (I already know its name), store the value and use it to give it as an argument to another executable.

So, a simple call like

./function2 5  // which comes from ./function2 Variable1 from above

I hope you understand the problem and can help me with it

  • 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-05-28T00:56:02+00:00Added an answer on May 28, 2026 at 12:56 am

    Easiest way to go is probably to use a combination of shell and perl or ruby. I’ll go with perl since it’s what I cut my teeth on. 🙂

    someExec.sh

    #!/bin/bash
    echo Variable1=5
    echo Another_Weird_Variable=12
    echo VARIABLENAME=42
    

    my_shell_script.sh

    #!/bin/bash
    myVariable=`./someExec | perl -wlne 'print $1 if /Variable1=(.*)/'`
    echo "Now call ./function2 $myVariable"
    

    [EDIT]
    Or awk, as Jaypal pointed out 58 seconds before I posted my answer. 🙂 Basically, there are a lot of good solutions. Most importantly, though, make sure you handle both security and error cases properly. In both of the solutions so far, we’re assuming that someExec will provide guaranteed well-formed and innocuous output. But, consider if someExec were compromised and instead provided output like:

    ./someExec
    5 ; rm -rf / # Uh oh...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Actually my question here is: are null and nil equivalent or not? I have
Quick bash/terminal question - I work a lot on the command line, but have
The question actually in it. Google Calendar provides a convenient API for access to
Problem This question actually came up at work today. We are planning an experiment
Actually my question is all in the title. Anyway: I have a class and
Now i know that this one is actually not a very technical question but
I feel rather silly actually asking this question as I am sure it will
I've actually posted this question before, but it hasn't been answered. Maybe I wasn't
the question sounds a bit confusing, but it is actually straightforward. This is a
the question sounds a bit confusing, but it is actually straightforward. This is a

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.