script:
#!/bin/zsh
IFS=$'\n' arr=($(alias | grep 'git' | grep "^[g|'g]" | sed 's/=.*//' | sed "s/'//"))
echo $arr
These two lines work in the normal command line:
~/test ····································································································································· test-Cj2sK_tx
❮ IFS=$'\n' arr=($(alias | grep 'git' | grep "^[g|\'g]" | sed 's/=.*//' | sed "s/'//"))
~/test ····································································································································· test-Cj2sK_tx
❯ echo $arr
g ga gaa gam gama gamc gams gamscp gap gapa gapt gau gav gb gbD gba gbd gbda gbl gbnm gbr gbs gbsb gbsg gbsr gbss gc gc!' gca gca!' gcam gcan!' gcans!' gcas gcasm gcb gcd gcf gcl gclean gcm gcmsg gcn!' gco gcount gcp gcpa gcpc gcs gcsm gd gdca gdct gdcw gds gdt gdw gf gfa gfg gfo gg gga ggpull ggpush ggsup ghh gignore gignored git-svn-dcommit-push gk gke gl glg glgg glgga glgm glgp glo glod glods glog gloga glol glola glols glp glum gm gma gmom gmt gmtvim gmum gp gpd gpf gpf!' gpoat gpristine gpsup gpu gpv gr gra grb grba grbc grbd grbi grbm grbo grbs grev grh grhh grm grmc grmv groh grrm grs grset grss grst grt gru grup grv gsb gsd gsh gsi gsps gsr gss gst gsta gstaa gstall gstc gstd gstl gstp gsts gsu gsw gswc gtl gts gtv gunignore gunwip gup gupa gupav gupv gwch gwip
However, it doesn't work when these two commands are in the script file...
~/test ····································································································································· test-Cj2sK_tx
❯ /bin/zsh ./d-alias.sh
# nothing here...
Thank you for any help. Many thanks.
zsh
shell does not read~/.zshrc
for non-interactive sessions (i.e. scripts). It does however read~/.zshenv
. It's questionable whether aliases should be defined therein. The user in the question may be better helped by converting their script into a shell function. – Kusalananda May 23 '21 at 14:57yash
,zsh
andbash
even though my Unix doesn't ship with any of those by default. You end up using the shell(s) you feel comfortable with, for the things it/they feel most suitable for. It's a bit like asking someone why they wrote a piece of code in any particular language. I'm not forced to use C just because my system ships with a C compiler. – Kusalananda May 23 '21 at 16:48bash
andzsh
have the programmable completion that ksh doesn't have, which is really convenient. I use command-line editing a lot, andbash
just does not do VI mode correctly; it always makes a mess of the line being edited.zsh
doesn't do it perfectly, but it's much better thanbash
, so I've been experimenting with it the past few months. Once I got the.profile
and.shrc
working, I've been generally happy withzsh
. And yes, I was very happy when AT&T released the source for ksh93, and the Linux distributions finally ditchedpdksh
. – Jeff Fisher May 23 '21 at 21:09