Score:1

How to list aliases (“alias” command) from within a script

in flag

I’d like to execute the “alias” command from within a script. It’s under the “Settings” area for the user. I can execute “env” but would like to follow that with their set aliases that they/I would see via the “alias” command. Is there a way to do this? I’ve tried:

if [[ "${command}" == "L" || "${command}" == "l" ]]                     
   then
      echo " "
      echo "Environment settings (env): "
      env
      echo " "
      echo "aliases: "
      `/bin/bash;alias`
      `alias`
      `echo ${BASH_ALIASES[]}`
      /bin/bash;alias
      alias
      echo ${BASH_ALIASES[]}
      echo " "
      echo "Done with Settings. Hit Enter to continue. "
      read settings_trash
   fi

But I always get nothing/null or a new shell.

Matthew Morrow avatar
in flag
Thanks sudodus that was just what I needed!
sudodus avatar
jp flag
You are welcome and good luck :-)
Score:2
jp flag

You need an interactive shell to see the aliases.

The following example with bash can probably help you fix a script

bash -c 'alias'  # does not see any alias

bash -ic 'alias' # sees a lot of aliases (in my system)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.