简体   繁体   English

有什么方法可以从Shell脚本文件打开登录Shell?

[英]Is there any way to open a login shell from a shell script file?

My script is called from a shell prompt. 我的脚本是从shell提示符下调用的。 Is there any way to ignore the immediate parent shell's properties. 有什么方法可以忽略直接父外壳的属性。

After I loging to my box. 登录到我的盒子后。 I run command like (say script1.sh), script1.sh sets the current environment to be used in the script1 context. 我运行命令(例如script1.sh),script1.sh设置要在script1上下文中使用的当前环境。

I have creates a script ( say script2.sh ). 我已经创建了一个脚本(例如script2.sh)。 I am planning to add some of the command in this script does not work in the context of script1.sh ( these command works before executing script1.sh). 我打算在此脚本中添加一些命令,该命令在script1.sh的上下文中不起作用(这些命令在执行script1.sh之前有效)。

Is there any way in which I can call some command in script2.sh which is not called in the context of script1.sh instead those commands should be called in new shell in the same condition as my login shell. 有什么方法可以在script2.sh中调用某些命令,而在script1.sh的上下文中不会调用这些命令,而是应在新shell中以与登录shell相同的条件调用这些命令。

If I understand your question, you can use: 如果我了解您的问题,则可以使用:

unset a

However, it is not very convenient, because it requires to unset one-by-one. 但是,它不是很方便,因为它需要一个一个地取消设置。 Looking forward to better solution. 期待更好的解决方案。

Its now only about environment variables. 现在只涉及环境变量。 When I execute script1.sh ( from my login shell) it opens up a new shell. 当我从登录外壳执行script1.sh时,它将打开一个新的外壳。

I want to achieve below manual commands in a single script on the current shell prompt assuming both script2.sh and script3.sh are available in PATH of my login shell: 我想在当前shell提示符下的单个脚本中实现以下手动命令,假设script2.sh和script3.sh在登录shell的PATH中均可用:

  1. script2.sh script2.sh

  2. exit # this will take me back to the login shell. 退出#这将带我回到登录shell。 Executing script3.sh from here is fine. 从这里执行script3.sh很好。

  3. script3.sh script3.sh

Now script3.sh is execute from my login shell and it works fine. 现在script3.sh是从我的登录shell执行的,它工作正常。

Is there any way to club the manual operations into a shell script? 有什么办法可以将手动操作整合到一个shell脚本中吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM