[英]Script command losing alias from shell
When I run the script command it loses all the aliases from the existing shell which is not desired for people using lots of aliases. 当我运行脚本命令时,它会丢失现有外壳中的所有别名,这对于使用大量别名的人来说是不希望的。 So, I am trying to see if I can automatically source the .profile again to see if it works without the user have to do it.
因此,我试图查看是否可以再次自动获取.profile,以查看它是否在无需用户执行的情况下起作用。
Here below is the code: 下面是代码:
#!/bin/bash -l
rm aliaspipe
mkfifo aliaspipe
bash -c "sleep 1;echo 'source ~/.bash_profile' > aliaspipe ;echo 'alias' > aliaspipe ;echo 'exec 0<&-' > aliaspipe"&
echo "starting script for recording"
script < aliaspipe
Basically I am creating a named pipe and the making the pipe as stdin to the script program, trying to run the source command and then close the stdin from pipe to the terminal stdin so that I can continue with the script. 基本上,我正在创建一个命名管道,并将该管道作为脚本程序的stdin,尝试运行source命令,然后关闭从管道到终端stdin的stdin,以便我可以继续执行脚本。
But when I execute, the script is exiting after I execute "exec 0<&-", 但是当我执行时,执行“ exec 0 <&-”后脚本将退出,
bash-3.2$ exec 0<&-
bash-3.2$ exit
Script done, output file is typescript
Not sure why the exit is called and script is terminated. 不知道为什么要调用该出口并终止脚本。 If I can make the script move the stdin from pipe to terminal then it should be fine.
如果我可以让脚本将标准输入从管道移动到终端,那应该没问题。
You can get script
to execute a bash
login shell by telling it to do so explicitly. 您可以通过明确指示执行
script
来执行bash
登录Shell。
# Gnu script (most Linux distros)
script -c "bash -l"
# BSD script (also Mac OS X)
script typescript bash -l
That will cause your .bash_profile
to be sourced. 这将导致您的
.bash_profile
被获取。
By the way, redirections are not stacks. 顺便说一句,重定向不是堆栈。 When you write
exec 0<&-
, you're closing standard input, and when bash's standard input is closed, it exits. 当您编写
exec 0<&-
,您将关闭标准输入,而当bash的标准输入关闭时,它将退出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.