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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:13:45+00:00 2026-06-10T10:13:45+00:00

I want to create bash aliases within a loop where the loop is reading

  • 0

I want to create bash aliases within a loop where the loop is reading lines from a command. In order to read output line-by-line, I believe I need to pipe the output into read. When I do that, however, the aliases don’t exist.

If I include the following in my .bashrc:

for x in a1 a2; do
    eval "alias $x='echo foo'"
done

echo -e "a3\na4" | while read x; do
    eval "alias $x='echo foo'"
done

Aliases a1 and a2 exist, but a3 and a4 do not. What is the difference between those two loops?

  • 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-10T10:13:47+00:00Added an answer on June 10, 2026 at 10:13 am

    The problem is the pipeline. In a pipeline of the form a | b | c, each of the individual commands a, b, and c is run in a separate subshell [ref], which means that it receives a copy of the parent’s execution environment (including aliases), and any changes it makes to its own copy (such as by running alias) will have no effect on the parent [ref].

    In your case, you could fix this by writing:

    while read x; do
        eval "alias $x='echo foo'"
    done < <(echo -e "a3\na4")
    

    which will still run echo -e "a3\na4" in a subshell, but will run the while-loop in the normal/parent execution environment.

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

Sidebar

Related Questions

In Bash, I want to create a file when the command succeed, otherwise create
I want to create a simple bash script to launch a Java program on
i want create multiple search where statement $where_search is a multiple condition from post
i want create a custom json data from the mssql 2008 results so that
I want to create a bash script that will launch two processes and kill
My bash fu is not what it should be. I want to create a
I want to create a symbolic link in Linux. I have written this Bash
My bash scripting is weak. I want to create a script that filters and
Hey I want to create a bash-shell in wxPython, the only thing it should
I am trying to create a shell script that pulls a line from 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.