Inheriting aliases within UNIX / usr / bin / script

The UNIX command "/ usr / bin / script" will create the current session decryption for your shell (see the "man script" for details).

However, when inside the script instance, it seems to forget the parent shell of env vars, aliases, etc.

The following example shows how the alias "ll" that I define is ignored inside the "script":

zsh> mkdir temp
zsh> cd temp

zsh> alias "ll=ls -alF"

zsh> ll
total 24
drwxr-xr-x   2 me   mygroup    4096 Feb 18 13:32 ./
drwxr-xr-x  28 me   mygroup    8192 Feb 18 13:32 ../

zsh> script a.out
Script started, file is a.out

$ ll

zsh: command not found: ll
$ exit
Script done, file is a.out

zsh> ll
total 32
drwxr-xr-x   2 me   mygroup    4096 Feb 18 13:32 ./
drwxr-xr-x  28 me   mygroup    8192 Feb 18 13:32 ../
-rw-r--r--   1 me   mygroup     182 Feb 18 13:32 a.out

So, how can I make the script process inherit the env settings from the parent shell?

[EDIT:] Alright, env vars are not forgotten. Just aliases. Re-sourcing.profile or something will work ... but how can I do this automatically ?

+3
5

, bash. , - zsh-, , zsh. : script -c zsh

zsh zsh.

+1

. .profile . $SHELL.

script . , .

+1

, . script.

script, , :

    $ alias myls="ls -lCF"
    $ alias -L >/tmp/alias.zsh
    $ script
    $ . /tmp/alias.zsh
    $ myls

.zshrc , .

0
0

zsh... .zshenv( .zshrc), .

, , ; >

alias foo='print FOO'
[khb@vm]~% foo
FOO
[khb@vm]~% script
Script started, file is typescript
[khb@vm]~% foo
zsh: command not found: foo
zsh: use 'exit' to exit.
[khb@vm]~% exit
Script done, file is typescript
[khb@vm]~% mv .bork .zshenv
[khb@vm]~% foo
FOO
[khb@vm]~% script
Script started, file is typescript
[khb@vm]~% foo
FOO
[khb@vm]~% 
 zsh: use 'exit' to exit.
Script done, file is typescript
[khb@vm]~% 
0

Source: https://habr.com/ru/post/1703451/


All Articles