Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I am using the command:
#!/bin/ksh
as the first line in my shell script (hopefully this will dictate the shell to execute in the KSH Shell) . But when i am executing my shell like below it is not actually happening.
sh test_shell.txt
But when i using like below with or with out (#!/bin/ksh) i am getting proper output.
ksh test_shell.txt
In my code i am setting a value to variable like below.
set -A variable_name
But i think -A is not recognized in sh where as it is working as an assignment in ksh shell.
How can I resolve this?
When you execute
sh test_shell.txt
then you are launching the sh (Bourne) shell with your file name as the script to run. In this case the first line of the script is ignored because it is a comment. The rest of the script is expected to be in Bourne shell syntax, because that's the shell you requested.
If you set your script to executable (chmod +x test_shell.txt) and then run it with:
./test_shell.txt
then the kernel will read the first line of the script, see it starts with the special #!, and run your script with /bin/ksh.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I've modified my .bashrc to mount directories when I start first terminal after login.
If mount point still exists when I start new terminal nothing is done.
Now I want to add a bit of code when last linux terminal is closed/exited (e.g. umount those directories, etc..)
Also there is this not-so-intelligent way of discovering how many terminal instances are still running:
ps -au | grep "bash" | grep "grep" -v -c
I'm running Ubuntu 20.04. and I'm using bash shell.
Questions:
Is there a file which is "triggered" on terminal exit just like .bashrc is on terminal startup? I've tried messing around with .bash_logout but it doesn't seem to do anything in my case (echo, touch..)
Is there another way to do what I'm trying to achieve which doesn't include file from question #1 (if such file even exists)?
You can get it done with the help of trap which is a shell builtin.
For example if you want to clear a folder on running exit command in bash >
trap "rm /cache/*" EXIT
The syntax should be like trap <command> <SIGNAL>
Just put this in the bottom of ~/.bashrc with your desired command and it should run before the terminal is killed.
Try trap --help to know more.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I opened terminal and run the command ps -aux |grep bash to learn the difference between Login Shell and Non-Login shell on my virtual machine's graphical interfaces (Ubuntu Desktop 16.04 x86).
But the output which shows both bash and -bash made me confused. I googled a lot to find out what the command -bash is, but I can only find something about bash, so I come for help.
It means bash is invoked as a login shell. This case it will have a hyphen before its name.
From man bash, section INVOCATION:
A login shell is one whose first character of argument zero is a -, or one started with the --login option.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
'Which' command gives the full path to the command. All other commands are working except cd command.
Think about how shells and changing directories work: For each command you enter it will start a new process for the command. Changing directory only applies to the currently running process. If the cd command was executed as an external command, then it would run it its own process, change its process directory, and then the process would exit and the parent process (the shell) would not know anything at all what the child process did.
Therefore the cd command can only be internal to the shell. It has to be parsed and executed completely by the shell and its own process.
cd is a builtin command in bash.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
When I try to execute the exec ls, my putty session is getting closed. What is the difference between ls and exec ls ?
Why do we need the exec command, and what are the uses of this command ?
exec replaces the current process (the shell) with the new process. If you call a program without exec, the shell will fork a new process and then replace the new process with the program.
exec is a shell built-in command.
In the manpage it says
If exec is specified with command, it shall replace the shell with command without creating a new process.
So when you execute exec ls in the shell, your shell will be replaced with the ls process; when this process ends, the shell exits. Compared with source or ., this could be useful in shell scripts.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
The commands which I ran and their outputs are given below -
$ echo $SHELL
/bin/bash
$ whence bash
sh: whence: command not found
$ which bash
/usr/bin/bash
I am not sure which shell I really have. First one says bash and the second says sh.
So, which shell is it ? bash or sh ?
This should clarify what you are using:
echo $BASH_VERSION
Check to make sure that /usr/bin isn't a link to /bin or vice-versa and that /usr/bin/bash isn't a link to /bin/bash or vice versa. It is possible that you are running one binary, /bin/bash, but that your path lists /usr/bin before /bin, in which case, which bash would list /usr/bin/bash - but that only means that /usr/bin/bash is the one you will run if you type bash on the command line. It doesn't mean it is the one you're running.