0

Differently from bash shell (for create new alias):

alias test="echo test"

if I do the same thing using a bash script, alias does not run:

#!/bin/bash
alias test="echo test"

also export it, same problem:

alias test="echo test" ; export test

maybe correct: really "test" in not a variable. So, how put any aliases to bash script and let them available in my environment?

1

This question has already been answered here.

helloworld.bash

#!/bin/bash
alias helloworld="echo helloworld"

Executing the script as follows:

[vagrant@localhost ~]$ . helloworld.bash

and [vagrant@localhost ~]$ helloworld results in:

[vagrant@localhost ~]$ helloworld
helloworld
1

alias is not available in a non interactive shell. Use bash's option -i. If the -i option is present, the shell is interactive.

#!/bin/bash -i
alias test="echo test"
test

Output:

test
  • -bash: test: command not found – 030 Nov 9 '14 at 19:54
  • @utrecht: You're doing something wrong. test is a shell builtin. – Cyrus Nov 9 '14 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.