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

  • Home
  • SEARCH
  • 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 8408777
In Process

The Archive Base Latest Questions

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

Problem: I’m running shell script as subprocess in ruby script, after running script I

  • 0

Problem:

I’m running shell script as subprocess in ruby script, after running script I want to have an option to check all environment variables of the shell, including array variables.

So far I have come up with:

set | awk -F= 'BEGIN            {v=0;}
  /^[a-zA-Z_][a-zA-Z0-9_]*=/    {v=1;}
  v==1 && $2~/^['\''\$]/        {v=2;}
  v==1 && $2~/^\(/              {v=3;}
  v==2 && /'\''$/ && !/'\'\''$/ {v=1;}
  v==3 && /\)$/                 {v=1;}
  v                             {print;}
  v==1                          {v=0;}
'

Which quite good shows only variables, including arrays, multiline strings and filtering out functions.

But this does not use the same format all the time, especially array variables are represented differently in BASH and ZSH.

Here is my current implementation: https://github.com/mpapis/tf/blob/master/lib/tf/environment.rb

Question:

Is there an easy way to show all the variables that will work persistently in BASH and ZSH / possibly other shells.

  • 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-09T23:43:29+00:00Added an answer on June 9, 2026 at 11:43 pm

    Nice to see you again mpapis 😉

    Unfortunately arrays and associative arrays are not covered by POSIX.1-2008, and as you have found there are some annoying subtle differences between bash and zsh. So there is no single way to do this across all POSIX shells, and we need to check $BASH_VERSION etc. as you already noted.

    I decided that it was better to avoid having to write Ruby to parse the output of set or other shell built-ins. The output is not convenient to parse, and anyway the shell knows the most about its own data, so I thought it made sense to put most of the intelligence inside the shell code. So instead I have come up with a solution which uses shell code to output the data structures as YAML, and then that YAML gets loaded directly into Ruby.

    First I imported your reference implementation and tests into the master branch of a standalone repository. Then I beefed up the test suite and made a few tweaks. This showed that there are still issues with the multi-line handling.

    Then I created a new yaml branch and developed my own implementation. Again I extended the tests. They all pass 😉 Notice that I use a few different tricks to do introspection in zsh and bash:

    • zsh has a zsh/parameter module which provides associative arrays containing the names and types of all its parameters.
    • bash has declare -p which is in an easily parseable form. It also has compgen -A variable, but in the end I didn’t use this.

    I think it would be easy to add ksh support too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
Problem: I have a table that prints out vertical but I would like it
Problem: I have two array where one produce a category and the second produce
Problem Using Director 11.5 and Windows 7, with MouseWheel Xtra (wheelmouse.zip), I have the
Problem Description: We have a service which has applications for main mobile OS’s. We
Problem! I Have the following input (rules) from a flat file (talking about numeric
Problem PHP session in different folder. I have problem with PHP session. There are
Problem statement: I want to upload a large binary (such as an audio clip)
Problem: I have 2 classes, DB class and a User class, that will work
Problem I have a xib file with a UIImageView over the top of the

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.