Use various methods to invoke a script, and determine when it runs in your shell, and when a subshell is created.
1) Using an editor or the cat command, write a korn or bash script that:
* Executes the ps command.
* Echos the value of the shell variable hi.
[root@vmpc_rh804 root]# cat > do-ps.bash
#!/bin/bash
# This script displays active processes
#
ps
echo $hi
2) Set the value of hi to hello in your current command line shell.
[root@vmpc_rh804 root]# hi=hello
3) Execute your script using the shell interpreter.
[root@vmpc_rh804 root]# bash do-ps.bash
PID TTY TIME CMD
1311 pts/4 00:00:00 bash
1358 pts/4 00:00:00 bash
1365 pts/4 00:00:00 ps
** Note that it doesn't recognize the hi variable. This is because the variable is local to the shell in which it was defined. When this script is executed, a new shell is started that is outside your local shell. **
4) Add execute privilege to the script file and run it as a command from the current directory.
[root@vmpc_rh804 root]# chmod +x do-ps.bash
[root@vmpc_rh804 root]# ./do-ps.bash
PID TTY TIME CMD
1311 pts/4 00:00:00 bash
1367 pts/4 00:00:00 do-ps.bash
1374 pts/4 00:00:00 ps
5) Use the built-in source command to execute the commands in the script file.
[root@vmpc_rh804 root]# source do-ps.bash
PID TTY TIME CMD
1311 pts/4 00:00:00 bash
1375 pts/4 00:00:00 ps
hello
[root@vmpc_rh804 root]#
** Note that it is able to recognize the hi variable. This is because the source command runs this script in the local shell. **
Nvidia new hotplug feature on Linux
-
If you use nvidia driver for your GPU, you probably wonder why in some
config, you can't hotplug your second monitor. You need to reboot to be
able to ...
10 months ago


No comments:
Post a Comment