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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:12:34+00:00 2026-05-31T18:12:34+00:00

I expect the answer to this is already here someplace, but I was not

  • 0

I expect the answer to this is already here someplace, but I was not able to find it. I’m wasting too much time messing around with this. Best to just ask and move on.

I am trying to create a (bash) shell script which when run will prompt for the name of an alias and the replacement string and then create that alias. So, being not the sharpest tool in the tool-shed, I tried (copied from a blog actually) the code below.

#!/bin/bash
echo "Enter the identifier for the alias (shortcut)"
read SHORTTEXT
echo "Now enter the string which $SHORTTEXT will alias:"
read LONGTEXT
alias $SHORTTEXT='$LONGTEXT'

I put the above code into the file ~/scripts/nojoy.sh, made the file executable, and then tried it out.

myid@myid:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 11.10
Release:    11.10
Codename:   oneiric
myid@myid:~$
myid@myid:~$ . ~/scripts/nojoy.sh 
Enter the identifier for the alias (shortcut)
testit
Now enter the string which testit will alias:
cd ~
myid@myid:~$ alias testit
alias testit='$LONGTEXT'

I then spend more time than I’ll admit to attempting to modify the clearly just plain wrong
alias $SHORTTEXT='$LONGTEXT'
into something which when the script was run would result in creating
alias testit='cd ~'
when the script runs.

I give up. Can someone please just explain to me how to do this so I can get on to doing something else more important than this? (Like cleaning litter boxes maybe?)


Update:

I did not expect to have a hard time picking an answer for this. But both answers work, albeit in different ways, and I’m not sure I appreciate whatever underlying subtleties there might be.

Using alias $SHORTTEXT="$LONGTEXT" in my script file together with the input string
find . -name '*.txt'
resulted in
alias test='find . -name '\''*.txt'\'''

Using eval "alias $SHORTTEXT='$LONGTEXT'" resulted in
alias test='find . -name *.txt'

I decided that my naive expectation of what the alias my shell script defined should do boiled down to pure text substitution. That is, if I defined an alias named
example for echo '*.txt' then when I used it I’d expect the result to be *.txt

Using the method in the first answer does this. The second answer does not. So I picked the first answer as closer to what I think I was looking for.

Thanks to all!

  • 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-31T18:12:35+00:00Added an answer on May 31, 2026 at 6:12 pm

    What you get is what the single quotes in:

    alias $SHORTTEXT='$LONGTEXT'
    

    demand. If you want $LONGTEXT expanded, use:

    alias $SHORTTEXT="$LONGTEXT"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question already has an answer here: Is there ever a reason to not
I'd expect this to be fairly routine, but cannot find a simple approach for
first: My technical problem is already solved, so this is not urgent, but I
I don't expect a straightforward silver bullet answer to this, but what are the
The answer to this question may be painfully obvious but I can't find it
I expect this might get some downvotes / closevotes but I'm going to ask
I expect that framework level updates (such as async) will not be able to
I'm having another fun problem with Rhino Mocks. Can anyone answer this one: Here's
You may find this weird, actually very weird, but is the following possible? just
This is my first time posting a question here, it has been a valuable

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.