0

I want to use the !!, !$,^abc^cde, etc. aliases in a bash script. Sadly, I cant seem to make them work in a script (They work just fine in interactive mode), Does anybody know what the problem is? If this can not be done, do you know about anything that operates in a similar way that can be used in a bash script?

1
  • What you're asking for is "history expansion". It's turned off by default in scripts, and is considered bad practice to use it in them anyhow. Commented May 12, 2013 at 16:38

1 Answer 1

1

Use set +o histexpand to enable history expansion in non-interactive bash shells.

Sign up to request clarification or add additional context in comments.

5 Comments

To be clear -- this is non-POSIX; it may work in bash scripts, but isn't guaranteed to work in any other shell.
@CharlesDuffy Well of course it is bash-specific. The question has the "bash" tag, and the question mentions bash in the question and in the title.
Sure. I didn't say it was wrong. Keeping track of what is and isn't portable is important.
@CharlesDuffy A Bash question gets a Bash answer and does not need a POSIX non-portability disclaimer, just like a Linux programming answer does not need a Windows non-portability disclaimer.
StackOverflow answers are for a general audience, not just the person originally asking the question. Answering the initial question is relevant to scoring and acceptance, sure, but it's worth making answers comprehensive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.