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. **
Second monitor no display after latest update - KDE-neon
-
After latest update as of Oct 3, 2023, my second monitor was undetected
with latest kernel (6.2.0-33-generic). If I boot with previous kernel, it
can be...
6 months ago
No comments:
Post a Comment