Skip to main content
19 votes
Accepted

Why does bash with "here documents" redirection start as interactive?

Why is this happening? Why is bash interactive in this case? It isn't. The outer - interactive - shell is expanding $- (the quotes aren't special in this context - compare bash -c "echo '$-'&...
steeldriver's user avatar
  • 83.8k
13 votes

Zsh clear scrollback buffer

function clear-scrollback-buffer { # Behavior of clear: # 1. clear scrollback if E3 cap is supported (terminal, platform specific) # 2. then clear visible screen # For some terminal 'e[3J' ...
Simba's user avatar
  • 1,992
13 votes
Accepted

Is possible to define a bash script to run interactively by default?

If you add the -i option to your hashbang(s) it will specify that the script runs in interactive mode. #!/bin/bash -i Alternatively you could call the scripts with that option: bash -i /path/to/...
jesse_b's user avatar
  • 41.5k
13 votes
Accepted

Is there some interactive analogue of `mktemp` that helps to organize throw-away directories?

It doesn’t quite cover all the features you mention (easily making the temporary directory persistent), but I rather like Kusalananda’s shell for this. It creates a temporary directory, starts a new ...
Stephen Kitt's user avatar
12 votes
Accepted

How to choose a response for interactive prompt during installation from a shell script

Configure the debconf database: echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections Then, install Wireshark: sudo DEBIAN_FRONTEND=noninteractive apt-...
Ugnius Malūkas's user avatar
10 votes

How can I make rm -rf ask for confirmation just once at the directory level?

With some rm implementations (DragonFly BSD where it comes from, FreeBSD and GNU at least), the -I (capital i) is what you are looking for. -i asks for confirmation for every file, while the -I (...
AsenM's user avatar
  • 598
9 votes

How can I disable the new history feature in Python 3.4?

As of Python 3.6, you can use readline.set_auto_history to disable this: import readline readline.set_auto_history(False)
Colin Watson's user avatar
  • 4,146
8 votes

Is possible to define a bash script to run interactively by default?

Sourcing your .bashrc is not a good idea. You could create a .bash_alias file with your alias and then source that file in your script and use shopt something like: shopt -s expand_aliases source ~/....
BANJOSA's user avatar
  • 731
7 votes
Accepted

Copying files interactively: "cp: overwrite"

The POSIX standard only specifies that the response need to be "affirmative" for the copying to be carried out when -i is in effect. For GNU cp, the actual input at that point is handled by a ...
Kusalananda's user avatar
  • 356k
6 votes
Accepted

Making mysql CLI ask me for a password interactively

Just have the user store the variable beforehand with read: echo "Please enter password for user ${domain}: "; read -s psw mysql -u root -p << MYSQL create user '${domain}'@'localhost' ...
dr_'s user avatar
  • 32.4k
6 votes

Why doesn't bash recognize alias in interactive mode?

So there is a hidden character in your command. This is copied directly out of your question: $ echo -n 'GCOM​ "\pushdict now ignores prefix macro."' | od -c 0000000 G C O M 342 200 ...
jesse_b's user avatar
  • 41.5k
5 votes
Accepted

Non-ascii chars are no longer displayed in bash

I'd say most likely your terminal is misconfigured and sends and displays characters in some single-byte character set, probably ISO8859-1 or ISO8859-15 given the sample characters you show instead of ...
Stéphane Chazelas's user avatar
5 votes

interactive SMTP command using telnet via a shell script

telnet fails for a variety of reasons. First up, if you strace it the relevant errors are telnet wanting a TTY on standard input, of which there is none (because of the redirect) so telnet fails. $ ...
thrig's user avatar
  • 35.8k
5 votes

Run script in a non interactive shell?

To run your script in a non-interactive shell (not regarding the details of cron), you can do this via ssh. Test if you really end up in a non-interactive shell: > ssh someuser@somehost tty not a ...
dokaspar's user avatar
  • 163
5 votes
Accepted

Is it possible to begin a sudo interactive session and also provide an initial command?

You could use --rcfile to tell bash to read your ps1.sh file instead of the service_user's .bashrc: sudo -i -u service_user bash --rcfile /home/me/ps1.sh The execution flow then will be something ...
muru's user avatar
  • 77.8k
4 votes

Why is Linux allowed to become unresponsive?

There is a workaround for the thrashing problem: to automatically limit system ressources per process user you can utilize the pam_limits module (via limits.conf) on Linux (CentOS and similar) or ...
Stefan's user avatar
  • 229
4 votes
Accepted

Can you enumerate all the ways to start an interactive shell?

“unless -s is specified” qualifies “without non-option arguments”. The synopsis for bash is bash [options] [command_string | file] Non-option arguments are command_string or file. If you specify ...
Stephen Kitt's user avatar
4 votes

Is there some interactive analogue of `mktemp` that helps to organize throw-away directories?

I just use cd $(mktemp -d) and then hack away. In general, the stuff exists for as long as I need it, but it goes away without any action on my part. I think my OS is configured (by default not by ...
emory's user avatar
  • 472
4 votes
Accepted

> symbol appearing when interactively defining function in bash

This has nothing to do with you installing nushell. It also does not stop the shell from functioning correctly. The > is the default value of the shell's secondary prompt (PS2). The secondary ...
Kusalananda's user avatar
  • 356k
3 votes
Accepted

Confused about determining if a shell script is running interactively

A shell script is, unless it's sourced by an interactive shell, very seldom run in an interactive shell environment. This means that $- would not include an i. What you could check is to see whether ...
Kusalananda's user avatar
  • 356k
3 votes
Accepted

sh: is there a command to interactively edit the PWD?

For bash and any other shell supporting readline you might be able to use this function icd() { local a; read -ei "${1:-$PWD}" -p "$FUNCNAME> " a && cd "$a"; } Usage icd # Starts ...
Chris Davies's user avatar
3 votes

Start new shell with positional parameters

You can use the -s option for that. From the POSIX description of sh: sh -s [-abCefhimnuvx] [-o option]... [+abCefhimnuvx] [+o option]... [argument...] -s Read commands from the standard ...
muru's user avatar
  • 77.8k
3 votes

Why no such non-interactive version of bashrc?

The conception function of ~/.bashrc file is to initiate correctly any shell which is: not the login shell, an interactive shell. Clearly the function of this shell script is to initiate environment ...
athena's user avatar
  • 1,085
3 votes
Accepted

Why no such non-interactive version of bashrc?

You already have the opportunity to set BASH_ENV to the pathname of a file that non-interactive shell script parse before running. This allows you to do, in a crontab for example @hourly BASH_ENV="$...
Kusalananda's user avatar
  • 356k
3 votes
Accepted

Confused about the meaning of an interactive and non-interactive shell when running a script

A shell running a script is a non-interactive shell. A non-interactive shell can still use e.g. read to read data from standard input. If standard input is a terminal, this may provide a level of "...
Kusalananda's user avatar
  • 356k
3 votes
Accepted

rm -iR does not work inside a loop

1. Why you example did not work as expected rm's prompts need STDIN to receive your feedback. In your example you used STDIN to pipe a list to the while loop though, thus rm was getting the answers ...
sborsky's user avatar
  • 1,088
3 votes

Which file is loaded and executed by a non-interactive non-login shell?

From man bash, in a non-interactive shell the BASH_ENV environment variable is evaluated and its content is sourced. So you could use that environment variable to specify a file with your environment ...
Thomas's user avatar
  • 6,632
3 votes
Accepted

PasswordAuthentication=no flag does not work on one strange host

debug1: Next authentication method: keyboard-interactive You're being prompted for "keyboard-interactive" authentication, which is technically separate from "password" ...
Kenster's user avatar
  • 3,587
3 votes
Accepted

Running a program outside of terminal

The background process: detaches from the terminal (setsid); runs xdg-open. If the terminal disappears before step 1 is finished, the whole process group receives a SIGHUP and is killed. setsid ...
Gilles 'SO- stop being evil''s user avatar
3 votes

Does tmux run-shell support interactive shell?

tmux run-shell subcommand does not work with programs that require tty. This explains why read fails when running in interactive mode[1] and also why tmux run-shell "echo start; read -p \"...
davidt930's user avatar
  • 409

Only top scored, non community-wiki answers of a minimum length are eligible