Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

-1 votes
1 answers
77 views
Why doesn't bash recognize alias in interactive mode?
How is this possible? ```none styx@LouSTyx:…$ GCOM​ "\pushdict now ignores prefix macro." GCOM​ : commande introuvable styx@LouSTyx:…$ type GCOM GCOM est un alias vers « git commit -a -m  » ```
How is this possible?
styx@LouSTyx:…$ GCOM​ "\pushdict now ignores prefix macro."
GCOM​ : commande introuvable
styx@LouSTyx:…$ type GCOM
GCOM est un alias vers « git commit -a -m  »
STyx (1 rep)
Jul 19, 2025, 01:01 PM • Last activity: Jul 26, 2025, 03:47 PM
15 votes
9 answers
14431 views
How can I disable the new history feature in Python 3.4?
Since upgrading to Python 3.4, all interactive commands are logged to `~/.python_history`. I don't want Python to create or write to this file. Creating a symlink to `/dev/null` does not work, Python removes the file and recreates it. The [documentation][1] suggests to delete the `sys.__interactiveh...
Since upgrading to Python 3.4, all interactive commands are logged to ~/.python_history. I don't want Python to create or write to this file. Creating a symlink to /dev/null does not work, Python removes the file and recreates it. The documentation suggests to delete the sys.__interactivehook__, but this also removes tab-completion. What should be done to disable writing this history file but still preserve tab-completion? Additional details: - Distro: Arch Linux x86_64 - readline 6.3-3 - python 3.4.0-2
Lekensteyn (21600 rep)
Mar 25, 2014, 03:38 PM • Last activity: Jun 19, 2025, 02:52 AM
8 votes
1 answers
892 views
Why does bash with "here documents" redirection start as interactive?
I found the following in `man bash` as a definition of interactive shell: > An interactive shell is one started without non-option arguments > (unless -s is specified) and without the -c option whose standard > input and error are both connected to terminals (as determined by > isatty(3)), or one st...
I found the following in man bash as a definition of interactive shell: > An interactive shell is one started without non-option arguments > (unless -s is specified) and without the -c option whose standard > input and error are both connected to terminals (as determined by > isatty(3)), or one started with the -i option. PS1 is set and $- > includes i if bash is interactive, allowing a shell script or a > startup file to test this state. So, interactive shell is the one that: 1. doesn't have non-option arguments (unless -s is specified), doesn't have -c option and whose standard input and error are both connected to terminal; or 2. has -i option I wrote the following example: ``` bash This type of redirection instructs the shell to read input from the > current source until a line containing only delimiter (with no > trailing blanks) is seen. **All of the lines read up to that point > are then used as the standard input** (or file descriptor n if n is > specified) for a command. It says that standard input is all lines read up to the delimiter (I assume that they are then passed to the command by redirecting the command's standard input to a pipe or something like that). Therefore, standard input is not (connected to) a terminal. Why is this happening? Why is bash interactive in this case?
Yakog (517 rep)
Feb 25, 2025, 09:12 PM • Last activity: Feb 25, 2025, 10:34 PM
0 votes
0 answers
51 views
Why Linux return strange result on mount of very old nfs2 share?
I have a directory shared with nfs2 from very old unix (Interactive unix 4.1.1) the directory is mount correct from Interactive Unix client. Trying with Linux I have this strange result sudo mount -o sec=sys,proto=udp,vers=2 -vv 192.168.0.15:/var/public /mnt/hd/ mount.nfs: timeout set for Tue Nov 5...
I have a directory shared with nfs2 from very old unix (Interactive unix 4.1.1) the directory is mount correct from Interactive Unix client. Trying with Linux I have this strange result sudo mount -o sec=sys,proto=udp,vers=2 -vv 192.168.0.15:/var/public /mnt/hd/ mount.nfs: timeout set for Tue Nov 5 13:42:02 2024 mount.nfs: trying text-based options 'sec=sys,proto=udp,vers=2,port=2049,bsize=32768,wsize=32768,rsize=32768,ac,acl,retry=1,retrans=2,addr=192.168.0.15' mount.nfs: prog 100005, trying vers=1, prot=17 mount.nfs: trying 192.168.0.15 prog 100005 vers 1 prot UDP port 1079 192.168.0.15:/var/public on /mnt/hd type nfs (rw,sec=sys,proto=udp,vers=2,port=2049,bsize=32768,wsize=32768,rsize=32768,ac,acl,retry=1,retrans=2) The share mount sucessfully but.. cd /mnt/hd/ ls /bin/ls: cannot access 'share': Too many levels of symbolic links share I have tried also removing all options (ac, acl, port..) but same result. Is a bug of nfs? Or there is a solution? On Linux client dmesg report VFS: Lookup of 'share' in nfs 0:58 would have caused loop The share "share" is a directory.
elbarna (13690 rep)
Nov 5, 2024, 12:45 PM • Last activity: Nov 5, 2024, 04:20 PM
1 votes
3 answers
2639 views
How to run an external program from bash, in an interactive manner?
For instance, if I want to run from a shell script something in python I would do: echo 'print("hello world")' | python2 Now imagine I want to run something interactive, i.e., it needs my input, for instance name = raw_input("Enter your name:") By doing: echo 'name = raw_input("Enter your name:")' |...
For instance, if I want to run from a shell script something in python I would do: echo 'print("hello world")' | python2 Now imagine I want to run something interactive, i.e., it needs my input, for instance name = raw_input("Enter your name:") By doing: echo 'name = raw_input("Enter your name:")' | python2 I get an error. So how is the correct way to run something from bash but that I can interact with? PS - this is simply an example. I need to run a set of scripts in a different external program (not python), and some of these scripts need some input from the user. Everything runs smoothly until the point when there is the need for input, where the current script crashes and passes to the next. Thanks :)
faeriewhisper (23 rep)
Oct 20, 2020, 11:59 AM • Last activity: Oct 6, 2024, 09:30 AM
0 votes
2 answers
2583 views
executing script on remote host using ssh does not return
We have several scripts on remotehost which we trigger from my localhost using ssh like below. ssh remuser@remhost sh /web/bin/stop.sh We had OS patching activity this weekend post which the above ssh command never returns and feels like it is hung or waiting for input. It may be difficult to get de...
We have several scripts on remotehost which we trigger from my localhost using ssh like below. ssh remuser@remhost sh /web/bin/stop.sh We had OS patching activity this weekend post which the above ssh command never returns and feels like it is hung or waiting for input. It may be difficult to get details regarding what patch was applied to the OS. Here are the details of the stop.sh cat stop.sh exec /usr/bin/java -jar /web/service.jar -DLOG_PATH=/web/logs --server.address=10.23.41.211 --server.port=10500 --spring.profiles.active=dev >> /web/logs/boot.log exit 0; First, we tried this solution from this forum but it does not return. ssh remuser@remhost 'sh /web/bin/stop.sh my.jar dev &> /dev/null closed We then tried the below and the ssh started returning but was unable to run the script on the remote host. ssh -fN remuser@remhost sh /web/bin/stop.sh my.jar dev Note: ssh remuser@remhost id does return and works fine. Other scripts also work fine. The issue is only with the scripts that have or >> where the control returns back to the invoker host. Can you please suggest? Note: There is no reason to debug the scripts. They are not the cause of issue as all the script are different and some very simple.
Ashar (527 rep)
Apr 20, 2021, 06:18 PM • Last activity: May 8, 2024, 09:45 AM
2 votes
3 answers
2027 views
Interactive commands with pipe and grep
There are commands such as `top`, `watch`, `Airodump-ng`, etc, that whenever you run, everything on the terminal change all the time. What I want to do is that run one of theses interactive command and then use pipe to grep something I've been looking for. Take this for instance: airodump-ng wlan0 |...
There are commands such as top, watch, Airodump-ng, etc, that whenever you run, everything on the terminal change all the time. What I want to do is that run one of theses interactive command and then use pipe to grep something I've been looking for. Take this for instance: airodump-ng wlan0 | grep "QQ:AF:00:55:8C:DF" In this example I am looking for a MAC address, when this MAC turn up, it will appear on screen so that I can grep it. The problem is that it doesn't work. I have searched a lot to no avail.
Kasra (77 rep)
Oct 15, 2016, 09:56 AM • Last activity: Apr 4, 2024, 12:54 PM
9 votes
4 answers
8350 views
How can I make rm -rf ask for confirmation just once at the directory level?
If I use `rm -rfi`, this asks me every time each file is deleted. If I have a list of `rm -rf` commands, how can I make it so that the machine asks me for confirmation just once (when trying to delete the directory itself)
If I use rm -rfi, this asks me every time each file is deleted. If I have a list of rm -rf commands, how can I make it so that the machine asks me for confirmation just once (when trying to delete the directory itself)
chintogtokh (191 rep)
Apr 16, 2019, 02:53 AM • Last activity: Mar 17, 2024, 03:28 PM
0 votes
1 answers
117 views
bash: How to prompt for user input while reading file?
Following script statement for user input is nested in while loop under if block but it doesn't work and is being skipped. How do I get user input to work? ```exec 3<&0 && read -p 'Enter your answer: ' uservar <&3``` ``` FILE="hostnames.txt" echo $(sudo chmod +777 $FILE) echo "Step 1. Checking if fi...
Following script statement for user input is nested in while loop under if block but it doesn't work and is being skipped. How do I get user input to work?
3<&0 && read -p 'Enter your answer: ' uservar <&3
FILE="hostnames.txt"
echo $(sudo chmod +777 $FILE)
echo "Step 1. Checking if file with hostnames exists."

#exec 3<&0

if [ -f "$FILE" ]
then
  echo "PASSED: File hostnames.txt does exist." && echo ""
  while IFS= read -r hostname;
    do
     echo "Step 2. Checking Grph mgmt_con_ip4 exists for $hostname"
     mgmt_con_ip4="$(echo "$(llama-grph node show $hostname | grep mgmt_con_i$
     echo "Grph has management IPv4 address: $mgmt_con_ip4"
     if [ -z $mgmt_con_ip4 ]
       then
         echo "PASSED: Grph mgmt_con_ip4 == NULL" && echo ""
       else
         echo "FAILED: Grph mgmt_con_ip4 == NOT NULL" && echo ""
         echo "$(ipam --format json get-cidr-parent $mgmt_con_ip4)" && echo ""
         echo "WARNING: OOB networks shouldn't have $mgmt_con_ip4 IPv4 addres$
         exec 3<&0 && read -p 'Enter your answer: ' uservar <&3
     fi
  done < $FILE
fi
Python_new (9 rep)
Mar 30, 2023, 11:27 PM • Last activity: Feb 15, 2024, 11:03 PM
1 votes
1 answers
178 views
Anyway to bind keyboard to dash (Debian Almquist Shell)?
Specifically Up/Down for history navigation. # What I already know I understand [`dash`](https://en.wikipedia.org/wiki/Debian_Almquist_shell#Dash) is a minimalistic, no bloat, (somewhat) strict POSIX shell. I understand the philosophy behind it, and the reason features, that have become basic in oth...
Specifically Up/Down for history navigation. # What I already know I understand [dash](https://en.wikipedia.org/wiki/Debian_Almquist_shell#Dash) is a minimalistic, no bloat, (somewhat) strict POSIX shell. I understand the philosophy behind it, and the reason features, that have become basic in other interactive shells, are not present in dash. I've looked into the following resources: * [man](https://www.man7.org/linux/man-pages/man1/dash.1.html) page * [Arch Linux Wiki](https://wiki.archlinux.org/title/Dash) page As well as a bunch of other pages and answers specific about history in dash. From my reading, I gather _there is_ a history mechanism, as well as a vi mode. However I can't find how to map the ` key, or the [UP]/[DOWN]` arrow keys (or any key) to any meaningful action. No bind or bindkey builtin commands either. My goal - make dash minimally usable as an interactive shell for debugging purposes. # Questions * Is there a default mapping? * Is there a way to manipulate the keyboard mapping in dash? * Is there another source of information that can shed some light on interactive usability of dash?
Lockszmith (768 rep)
Jan 11, 2023, 10:58 PM • Last activity: Jan 11, 2024, 06:37 AM
1 votes
3 answers
265 views
How to interactively edit a file name from the terminal like with a file manager?
At the command line, one can rename a file by specifying the entire new name to `mv` mv oldname newname or using a regex with e.g. Perl's `file-rename` command. rename -d 's/old/new/' oldname But is it possible to interactively rename a file by manually moving a cursor and changing bits of it, like...
At the command line, one can rename a file by specifying the entire new name to mv mv oldname newname or using a regex with e.g. Perl's file-rename command. rename -d 's/old/new/' oldname But is it possible to interactively rename a file by manually moving a cursor and changing bits of it, like when one renames a file in a file manager? File-manager rename
Nahoj (129 rep)
Oct 22, 2023, 09:25 AM • Last activity: Oct 26, 2023, 04:57 PM
2 votes
1 answers
633 views
Does tmux run-shell support interactive shell?
I know tmux run-shell can execute shell: ``` $ tmux run-shell "echo start; echo \${var}end" start end ``` But what if I want my shell could work interactively or read some user input, ``` $ tmux run-shell "echo start; read -p \"prompt:\" var; echo \${var}end" start end ``` - Why read statement in ab...
I know tmux run-shell can execute shell:
$ tmux run-shell "echo start; echo \${var}end"
start
end
But what if I want my shell could work interactively or read some user input,
$ tmux run-shell "echo start; read -p \"prompt:\" var; echo \${var}end"
start
end
- Why read statement in above code doesn't work? - Could any tmux expert let me know ways to implement interactive action with tmux? Background: - I put my various common work into a single kit.sh as functions all the time - There are many interactive questions in this script - Now I want to reuse this kit.sh with tmux hot key, as bind-key i "run-shell \"kit.sh\"" in my .tmux.conf - I'm planing to add some tmux send-keys in this kit.sh for kind of auto-type functions **Update 20231016:** My problem is solved as
bind-key i "new-window \"/path/to/my/kit.sh\""
And in kit.sh I can read user input interactively.
Qiu Yangfan (204 rep)
Oct 13, 2023, 04:34 AM • Last activity: Oct 16, 2023, 06:40 AM
0 votes
2 answers
216 views
Change behavior of bash script if executed from another script
I have a script (say `Task.sh`) (with executable permission): Pseducode: ``` if [[ Not called from inside a script ]]; then echo 'Not called from inside a script' else echo 'Called from a script' fi ``` --- I have a script say `Main.sh` (with executable permission): ```bash Value=$(Task.sh) echo "${...
I have a script (say Task.sh) (with executable permission): Pseducode:
if [[ Not called from inside a script ]]; then
  echo 'Not called from inside a script'
else
  echo 'Called from a script'
fi
--- I have a script say Main.sh (with executable permission):
Value=$(Task.sh)
echo "${Value}"
--- # Expected Outcome
$ Task.sh
Not called from inside a script

$ Main.sh
Called from a script
# Help Request Please suggest what conditional to put in the pseducode for Task.sh
Porcupine (2156 rep)
Oct 3, 2023, 08:26 PM • Last activity: Oct 7, 2023, 10:53 AM
0 votes
0 answers
74 views
How to regain script interactivity when `... | bash` best practices?
Let's say we have a simple script named `question`: ```bash #!/bin/bash read -rp "What's your name?" ans echo "Your name is $ans" ``` Let's use `cat` for our example ``` cat question | bash ``` We feed the content of the script file to the standard input of Bash and execute it as a command. When exe...
Let's say we have a simple script named question:
#!/bin/bash

read -rp "What's your name?" ans

echo "Your name is $ans"
Let's use cat for our example
cat question | bash
We feed the content of the script file to the standard input of Bash and execute it as a command. When executed the standard input of bash is used, so nothing past the pipe is possible to be fed to standard in, unless put before the pipe. To mitigate this, an option is to download the content of the script file first pass it to the shell and only then execute it.
bash -c "$(cat ./question)"
Another option I found for the syntax ... | bash is that in the script, if we replace the current process with a new one where the stdin is redirected from the terminal, wrapped in a subshell it works, as follows:
#!/bin/bash

(
 exec < /dev/tty

 read -rp "What's your name?" ans

 echo "Your name is $ans"
)
I wonder what other options exist there or what'd be the best practice.
punkbit (111 rep)
Oct 6, 2023, 11:17 AM
0 votes
0 answers
428 views
Open GUI linux terminal in non-interactive mode
It would be helpful if I can open a terminal and run commands exactly as if they would be run by a non-interactive bash script, to test whether certain commands work in non-interactive mode without having to make a script for it. Is this possible? To be clear I don't mean to set the terminal to non-...
It would be helpful if I can open a terminal and run commands exactly as if they would be run by a non-interactive bash script, to test whether certain commands work in non-interactive mode without having to make a script for it. Is this possible? To be clear I don't mean to set the terminal to non-interactive mode after having started, since at that point it will already have run e.g. .bashrc thereby changing the environment. For example, suppose I have a command test_command file1.txt, but test_command is defined in .bashrc. Then since in non-interactive mode the command won't be found, it shouldn't work in this terminal either.
user56834 (137 rep)
Sep 18, 2023, 03:26 PM • Last activity: Sep 18, 2023, 03:46 PM
6 votes
1 answers
3100 views
Prompt for confirmation for every command
I'm writing a pretty ad-hoc install script for some thing. No much control constructs, basically just a list of commands. I'd like the user to confirm each command before it gets executed. Is there a way to let bash do that, without prefixing every command with a shell function name?
I'm writing a pretty ad-hoc install script for some thing. No much control constructs, basically just a list of commands. I'd like the user to confirm each command before it gets executed. Is there a way to let bash do that, without prefixing every command with a shell function name?
MvG (4551 rep)
Apr 12, 2013, 01:36 PM • Last activity: Aug 24, 2023, 03:19 PM
1 votes
0 answers
204 views
zsh vared: how to define custom completion?
I would like to launch a command that would read user input and pass each line as a new task to TaskWarrior: ``` #!/bin/zsh set -e while vared -p 'task add> ' -eca task; do eval task add "${task[@]}"; done ``` Now I would like to have the `vared` input line to have access to any relevant `task add`...
I would like to launch a command that would read user input and pass each line as a new task to TaskWarrior:
#!/bin/zsh
set -e

while vared -p 'task add> ' -eca task; do eval task add "${task[@]}"; done
Now I would like to have the vared input line to have access to any relevant task add completions – the input/completion should behave the same as if I had a regular shell and already typed task add into it. I tried messing around with the $words parameter, but got no discernable effect.
khardix (11 rep)
Mar 30, 2023, 10:43 AM
0 votes
2 answers
71 views
> symbol appearing when interactively defining function in bash
The behaviour of my shell environment changed: Earlier, when pasting a function definition e.g. function exampleFunc { echo hello } to the shell, it would display as formatted and register the new function definition. Now, for some reason, it displays with `>` before each line other than the first....
The behaviour of my shell environment changed: Earlier, when pasting a function definition e.g. function exampleFunc { echo hello } to the shell, it would display as formatted and register the new function definition. Now, for some reason, it displays with > before each line other than the first. function exampleFunc { >echo hello >} I've found that functions containing for loops now fail to be registered. What might be an explanation for this? How might I revert back to the previous mode? --- Ubuntu 20.04 This change occurred after installing nushell , but maybe unrelated.
Lee (549 rep)
Mar 11, 2023, 02:38 PM • Last activity: Mar 11, 2023, 04:09 PM
15 votes
2 answers
11283 views
Zsh clear scrollback buffer
With Bash Ctrl L will clear the screen but not scrollback buffer. In the past I have worked around this by using: tput reset However I have noticed that this command will not clear the scrollback buffer with Zsh. So, how is it done?
With Bash CtrlL will clear the screen but not scrollback buffer. In the past I have worked around this by using: tput reset However I have noticed that this command will not clear the scrollback buffer with Zsh. So, how is it done?
user327359
May 3, 2019, 10:16 PM • Last activity: Feb 22, 2023, 08:51 AM
1 votes
0 answers
73 views
A script causes a parent script to stop
I have a third-party script that runs some complicated stuff. I run everything from an ssh session (the machine is a headless VM running Ubuntu 20.04). When I run it interactively, it runs normally. $ ./third-party-script.sh one $ ./third-party-script.sh two When I run it from another script, the pa...
I have a third-party script that runs some complicated stuff. I run everything from an ssh session (the machine is a headless VM running Ubuntu 20.04). When I run it interactively, it runs normally. $ ./third-party-script.sh one $ ./third-party-script.sh two When I run it from another script, the parent script stops when the third-party script executes for the *second* time. $ cat my-script.sh #!/bin/sh ./third-party-script.sh one ./third-party-script.sh two $ $ ./my-script.sh + Stopped ./my-script.sh $ I can send my script to foreground and it continues normally $ fg $ What could be the reason of this behaviour and how can it be avoided? I cannot fix the third-party script or anything that it runs, I can only fix my script. (The original "my-script" is written in Python and uses os.system, I simplified it to a bare-bones shell script for this question). I tried running the script with nohup but it didn't help. Thanks to @ilkkachu, I have narrowed it down to the third-party script executing bash -ic some_command. So the minimal script that reproduces this in *my* environment is: #!/bin/sh bash -ic ls bash -ic ls sh -ic and bash -c both fix the problem. Unfortunately I cannot change the command. I need to *wrap* the third-party script somehow so that it stops doing this. I tried bash -icx instead, but this doesn't narrow down the problem any further. The second bash execution stops before printing any command. I tried to strace -f the whole thing and this is what comes in the end: [pid 3805453] ioctl(255, TIOCGPGRP, ) = 0 [pid 3805453] rt_sigaction(SIGTTIN, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f131f36a090}, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER, sa_restorer=0x7f131f36a090}, 8) = 0 [pid 3805453] kill(0, SIGTTIN) = 0 [pid 3805321] 0x7ffcc2d45bfc, 0, NULL) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) [pid 3805453] --- SIGTTIN {si_signo=SIGTTIN, si_code=SI_USER, si_pid=3805453, si_uid=4437} --- [pid 3805321] --- SIGTTIN {si_signo=SIGTTIN, si_code=SI_USER, si_pid=3805453, si_uid=4437} --- [pid 3805453] --- stopped by SIGTTIN --- [pid 3805321] --- stopped by SIGTTIN --- 3805453 is the *second* child bash running -ic ls and 3805321 is the top-level bash running my-script.sh. It is the only line with kill(0, SIGTTIN) in the strace log. The first child bash doesn't do anything like that, only the second one does.
n. m. could be an AI (416 rep)
Feb 6, 2023, 10:55 AM • Last activity: Feb 6, 2023, 12:56 PM
Showing page 1 of 20 total questions