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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:27:58+00:00 2026-06-09T04:27:58+00:00

In my project, we have a shell script that sets default values for some

  • 0

In my project, we have a shell script that sets default values for some environment variables. When I try to run rinari-console, I receive an error because the script has not been sourced. Is there a way to make sure rinari sources it, so that when the rails console starts, all the variables have the needed values?

  • 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-09T04:27:59+00:00Added an answer on June 9, 2026 at 4:27 am

    Alright I’ve been thinkg a bit harder about the question. I’ve come up with two possible solutions:

    Outside Emacs via wrapper

    This solution is a bit clumsy, but it should work.

    You could create a wrapper script, e.g. ’emacs-wrapper.sh’:

    #!/bin/sh
    set -a
    . YOUR-SCRIPT.sh
    emacs
    

    If you launch ./emacs-wrapper.sh, YOUR-SCRIPT.sh will be sourced and Emacs is started after that. The same environment will be visible to Emacs this way. Testing this approach on my machine, I was able to (getenv “var”) all variables defined in YOUR-SCRIPT.sh

    Nicer: Within Emcas via shell-command

    This is IMO a much nicer solution since it runs completely inside Emacs. Makes a call to shell-command-to-string to source your YOUR-SCRIPT.sh. At the end it also dumps that process’ environment. This is subsequently added to Emacs’ own process-environment:

    ;; defadvice is optional, you could also just call source-script directly
    (defadvice rinari-console (before init-environment activate)
       (source-script "/PATH/TO/YOUR-SCRIPT.sh"))
    
    (defun source-script (script)
       (let ((env (extract-environment script)))
           (mapc 'import-environment-variable (split-string env "\n"))))
    
    (defun extract-environment (script)
       (shell-command-to-string (format "set -a; . %s > /dev/null 2>&1; env" script)))
    
    (defun import-environment-variable (variable-assignment)
       (when (not (or (null variable-assignment) (string= "" variable-assignment)))
          (let* ((key-value-pair (split-string variable-assignment "="))
                 (key (car key-value-pair))
                 (value (cadr key-value-pair)))
            (setenv key value))))
    

    I verified this approach on my machine as well. All variables defined in YOUR-SCRIPT were also defined in Emacs.

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

Sidebar

Related Questions

I have a project that generates a shell script at CMake time (with file(WRITE
I have an old project at our company that uses shell scripting a lot.
My project have no visible error but when i try to run it gives
I have a python script that connects to an external host, fetches some data,
I have some shell script where I want to check one of my git
I'm working on a project that essentially creates files via a shell script using
I've got a nice power-shell driven post-build script that does some magic mumbo-jumbo for
I have a C++ project that have like 15+ external libraries installed with a
I have an iPhone SDK project that is supposed to build a static library
I have an iOS app project in Xcode 4.2. I also have a shell

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.