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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:42:47+00:00 2026-06-07T05:42:47+00:00

I am returning strings from a python module, for consumption within a bash script.

  • 0

I am returning strings from a python module, for consumption within a bash script.

This is what I have so far:

SCRIPT_DIR=/somepath/to/scripts/folder
cd $SCRIPT_DIR/eod

python_cmd='import sys;
            sys.path.append("/somepath/to/scripts/folder/utils"); 
            import settings as st; 
            print " ".join(st.foo())'

# Fix indentation for Python
python_cmd=${python_cmd//'            '/''}

my_array=(`python -c "$python_cmd"`)

I want to use the DRY philosophy in the snippet above. However, the string/somepath/to/scripts/folder is repeated in the script. I would like to pass the definition of $SCRIPT_DIR into the python_cmd – however I tried (replacing the path string in python_cmd with $SCRIPT_DIR/utils and it failed with the following error:

Traceback (most recent call last):
  File "<string>", line 3, in <module>
ImportError: No module named settings

What am I doing wrong?

Note:

I am running bash 4.1.5

  • 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-07T05:42:48+00:00Added an answer on June 7, 2026 at 5:42 am

    Don’t bother to pass the string in at all. Instead of modifying sys.path in the Python text, modify the PYTHONPATH environment variable in the bash script. It’s easier, and is the preferred way to affect the import path anyway.

    An example of how to set the path:

    SCRIPT_DIR=/somepath/to/scripts/folder
    cd $SCRIPT_DIR/eod
    
    export PYTHONPATH=$SCRIPT_DIR
    python_cmd='import settings as st; 
                print " ".join(st.foo())'
    

    I also have to say, this seems like an odd way to glue components together, but I don’t have enough information to recommend a better way.

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

Sidebar

Related Questions

This is a question about returning efficiently strings and chars from a string array
I have an external module, that is returning me some strings. I am not
I have the following string: monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date and the following Python script: from datetime import
I have this code for Jaro-Winkler algorithm taken from this website. I need to
I have a textbox which can return various strings ranging from 5 characters upto
In my python code I have this line: try: result = eval(command, self.globals, self.locals)
In some methods returning strings, I have often seen returned if the actual string
I am returning string Subject from this class now if i want to return
I am returning a string of either T or F from an NSDictionary key
I'm returning data from a HttpGet and then passing the string(s) into a Listview

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.