在UNIX / usr / bin / script内继承别名 [英] Inheriting aliases inside UNIX /usr/bin/script

查看:133
本文介绍了在UNIX / usr / bin / script内继承别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



然而,UNIX/ usr / bin / script命令将创建一个运行的shell会话的脚本(请参阅man脚本了解更多信息) ,当一个脚本实例,似乎忘记了父shell的env vars,别名等。



以下示例演示了 ll别名我定义在脚本内被忽略:

  zsh> mkdir temp 
zsh> cd temp

zsh>别名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>脚本a.out
脚本启动,文件是a.out




$ ll

  zsh:command not found:ll 




  $ exit 
脚本完成,文件是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

所以,如何让脚本进程从父shell继承env设置?



好的,env vars是没有忘记。只是别名重新采购.profile或某些工作...但是如何才能使自动发生

解决方案

当我在bash下启动它时,它可以正常工作。也许在您的zsh配置中有一些东西被弄脏了,或者它不是源自你的zsh的启动文件。您可以尝试:
脚本-c zsh



哪些可能会迫使它启动一个新的zsh shell并让它来源您的zsh配置文件。


The UNIX "/usr/bin/script" command will create a running transcript of your shell session (see "man script" for more info).

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

The following example demonstrates how the "ll" alias I define is ignored inside "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 get the "script" process to inherit the env settings from the parent shell?

[EDIT:] Okay, env vars are not forgotten. Just the aliases. Re-sourcing the .profile or something would work... but how can I make that happen automatically?

解决方案

It works OK when I start it under bash. Maybe there's something in your zsh configuration that's mucking it up, or it's not sourcing your zsh's startup files. You could try: script -c zsh

Which may force it to start a new zsh shell and have it source your zsh config files.

这篇关于在UNIX / usr / bin / script内继承别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆