1

I have created a simple script to setup an alias on an ESXi 6.7 host:

#!/bin/sh
alias ll="ls -la"
echo "Profile done"

When I run the script I see the echo'd message on screen, but the alias is not set. But if I execute the alias command from a command prompt it works fine.

Can someone explain how to setup an alias from a script?

TSG
  • 1,674
  • 7
  • 32
  • 51

1 Answers1

3

For me this works as expected. Make sure that you dot source the script like this:

. ~/.profile

instead of executing it like this

~/.profile

The latter spawns a new shell process where the alias is created, but then terminates the spawned shell, leaving the original calling shell unmodified.

If you save your script as ~/.profile it will also get properly sourced when you log off and log in again.

VFrontDe
  • 1,508
  • 8
  • 13