Questions tagged [shell]

The shell is Unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks. Use this tag for questions applying to /bin/sh and most compatible shells (ash, bash, ksh, zsh, …). For shell scripts with errors, please check them in http://shellcheck.net before posting here.

Filter by
Sorted by
Tagged with
2 votes
3 answers
239 views

Two ssh output as awk input

I have two remote servers that I am trying to ssh and cat some files.. I want to input the output of the ssh to a awk command. This is what I have got ssh username@host1 “cat /tmp/test/*” ssh ...
NecroCoder's user avatar
0 votes
1 answer
29 views

Find file in directories of PATH env which match partially

Idea is to match a filename in any of directories mentioned in PATH environment. Usually, we do this by running "which <executable_filename>". This works fine, when the file your are ...
Sachin's user avatar
  • 3
1 vote
0 answers
17 views

Is there a way to change text size on a console screen, specifically XAMPP shell console?

I simply just want to be able to display the text at a smaller size as it currently is too large and messes with the display of the output (at least on my laptop screen which isn't all too big, but ...
schoolstudent's user avatar
0 votes
1 answer
30 views

how to source tmux session_id into tmux

I have this: export session_uuid="$(uuidgen)" remove_session() { tmux kill-session -t "$session_uuid" } export -f remove_session trap remove_session TERM INT SIGINT SIGTERM ...
Alexander Mills's user avatar
0 votes
1 answer
65 views

Upload a file with SSH and then give back the control to the user

I'm trying to create a script that, when you connect on a remote server with SSH, the script checks things and deploy your personals scripts before giving you back the stdin, all in one SSH connection ...
Shengis's user avatar
1 vote
1 answer
33 views

How to disable "long descriptions" of commands in ZSH

I have a program named fhome that provides shell completion for Zsh: $ fhome <tab> config -- Manage system configuration event -- Manage events help h -- Shows a list of commands or ...
Bartek Pacia's user avatar
0 votes
0 answers
29 views

why does ZSH pass # and arguments following to process? [duplicate]

I did some experimenting and: alex.mills@alex wss % node /Users/alex.mills/codes/vibeirl/wss/scripts/arg-test.js -v a # 3 [ '/Users/alex.mills/.nodenv/versions/14.17.0/bin/node', '/Users/alex....
Alexander Mills's user avatar
2 votes
2 answers
169 views

How to run all scripts of the form `sh my_dir/subdir*/qsub.sh`

I have several directories of the form: my_dir/subdir*/qsub.sh I want to execute all of the qsub.sh in each of these subdirectories, but when I tried to do sh my_dir/subdir*/qsub.sh it seems to only ...
roulette01's user avatar
1 vote
0 answers
38 views

Sudoers env_keep wildcard expression with exceptions

When running sudo, I'm trying to retain all environment variables related to the Borg backup program, with 2 exceptions. Using env_keep in my sudoers config (with env_reset enabled), here is what I ...
SpinUp __ A Davis's user avatar
-1 votes
2 answers
89 views

How can I get a file list, recursively?

I would like to have output with the following format: /media/username/New/Audio/time machine by Ariya Hedie.mp3 /media/username/New/Audio/You areever alone by Dj Quads.flac /media/username/New/Audio/...
stax76's user avatar
  • 101
1 vote
1 answer
146 views

How to run the command "sudo sh /path/to/script.sh" by double clicking?

I have a question from this thread How to run a bash script by double clicking by entering the path in sudoers?. Since it was explained to me that it is unsafe to grant sudo privileges to the script....
moninah's user avatar
  • 15
4 votes
1 answer
206 views

Is there a away to override a shell's non-interactive state?

A big company, jealous guardian of their highly customized Unix flavor, is restricting code-signing to interactive shells. We, however, would like our gitlab-runner to sign software products as part ...
Gruber Hans's user avatar
0 votes
1 answer
61 views

multiple commands in linux shell

I have just come across an article describing process of installing containerD runtime and I'm a little dubious about the command mentioned, maybe a typo but I want to get clarity on it. The command ...
JayD's user avatar
  • 103
-1 votes
0 answers
21 views

How to deal with unresponsive shell on the server?

I am working on a binary exploitation challenge. I was able to interact with the server successfully by responding with a correct response. Looks like I gain a shell (normal user), and I am supposed ...
noob's user avatar
  • 1
-1 votes
2 answers
73 views

How does the `tr` command work?

I was playing around with tr and got some unexpected results. What is happening in these situations? I don't understand what is happening under the hood, or perhaps I'm not using this command ...
BadHorsie's user avatar
  • 141
0 votes
0 answers
33 views

Strange incongruent output for both nc and fifo

I have this exact code: #!/bin/bash gtimeout(){ if type -f gtimeout &> /dev/null; then command gtimeout "$@" else timeout "$@" fi } export -f gtimeout; ...
Alexander Mills's user avatar
0 votes
1 answer
42 views

How to execute a subshell directly

I have this: timeout 25 bash -c ' for i in {1..9}; do if read line < "$my_fifo"; then if test "$line" != "0"; then exit 0; ...
Alexander Mills's user avatar
-1 votes
0 answers
49 views

script to exit 0 when stdin match is made

I need to wait for a server to actually start listening before initiating a new process, something like this: mkfifo my_fifo ( timeout 15 docker logs -f rabbitmq | on_first_match 'ready for ...
Alexander Mills's user avatar
6 votes
3 answers
2k views

How to referencing $@ without pass it in bash function?

I wants to know how can I reference the $@ from another function or another script file without pass it just like what getopts do. Thank you very much! # previous question : How bash getopts get to ...
Till's user avatar
  • 193
2 votes
1 answer
265 views

How bash getopts knows what arguments the call has

If getopts is a bash function, by my understanding, you need to pass $@ - the whole arguments to getopts to let the function know what kind of arguments you have in order to proceed, right? It seems ...
Till's user avatar
  • 193
0 votes
0 answers
50 views

How to run a process in the background using a bash script? [duplicate]

When I run the command in the terminal: sudo badvpn-tun2socks --tundev tun0 --netif-ipaddr 10.0.0.2 --netif-netmask 255.255.255.0 --socks-server-addr 127.0.0.1:8080 I get a terminal with packet data ...
moninah's user avatar
  • 15
5 votes
0 answers
119 views

Is there a command to run an executable?

bashenables to run bash scripts with bash somescript, python python scripts with python3 somescript. Alternatively, with the right shebang, I can run directly the previous scripts with ./somescript. ...
lalebarde's user avatar
  • 203
1 vote
1 answer
50 views

How to convert all newlines to "\n" in POSIX sh strings

I have a string that contains newline characters. I want to escape all newlines in that string by replacing all newline characters with a string of two characters: "\n". How can I do this in ...
Flux's user avatar
  • 2,770
0 votes
0 answers
23 views

why the nohup background process did not started

I am using this script to startup my application: #!/usr/bin/env bash set -u set -e set -x nohup pdm run python3.10 /root/visa/main_api.py > /root/visa/starup.log & tail -f /root/visa/starup....
Dolphin's user avatar
  • 589
4 votes
3 answers
223 views

How to sort the list of positional parameters in POSIX sh

Is there a way to sort the list of positional parameters in POSIX sh? Each positional parameter could contain arbitrary characters (e.g. spaces, newlines, tabs, etc.). The sort algorithm should be ...
Flux's user avatar
  • 2,770
2 votes
3 answers
742 views

ARGV[] not accepting the argument

I have a shell script that I am trying to pass a date argument to ARGV[1] but the script is giving a blank output Here is the command: #!/bin/bash dt=$(date -d "yesterday" '+%m%d%Y') cat /...
NecroCoder's user avatar
0 votes
1 answer
33 views

Set PATH for /bin/sh in Debian:11 image

Background I am building an image based on Debian:11. I am trying to set the PATH for the /bin/sh with a dynamic value determined at image build-time. (The "at image build time" is important....
Wallace Kelly's user avatar
1 vote
1 answer
80 views

How to decode base64-encoded inline attachments in email files saved from Thunderbird or Gmail?

Although base64 [--decode] works well when encoding and decoding files locally, I can't decode a base64-encoded inline attachment in an eml file saved from Thunderbird or Gmail. I observed that base64-...
Sadi's user avatar
  • 475
-1 votes
1 answer
69 views

sh split value into variables

This works on the command line, but not in a script. read -r local_temperature system_mode preset running_state current_heating_setpoi nt <<< $(thermostat) Syntax error: redirection ...
Richard Barraclough's user avatar
0 votes
2 answers
68 views

Add a process to an already executing process? Like && or so

This question inspired me to another related question. Imagine that you start % nohup a.sh & and then want b.sh to execute when a.sh is finished (E.g., b.sh will process the output from a.sh. ...
d-b's user avatar
  • 1,853
-1 votes
0 answers
19 views

Consistent Ansible Playbook Fails on Specific Servers with RPM Digest Mismatch [duplicate]

I'm facing an issue with an Ansible playbook named checkmk_playbook.yml, which installs check_mk on our servers. It executes without issues on servers [servernameaprhel003], [servernameaprhel002], and ...
jspaine's user avatar
  • 11
-2 votes
0 answers
38 views

ERROR! conflicting action statements: command, ignore errors [duplicate]

I am experiencing a persistent issue with an Ansible playbook that is intended to forcefully install the check_mk_agent on a number of Red Hat Enterprise Linux servers. The playbook works as expected ...
jspaine's user avatar
  • 11
0 votes
1 answer
81 views

A && B || C vs if then else fi [duplicate]

Stéphane commented that A && B || C cannot be used in place of proper if then else fi Can someone explain what's the difference?
Tom Huntington's user avatar
-2 votes
2 answers
110 views

defining variables inside function

After some reading somewhere on this interwebs, I found that it was best practice to to the following when using the output of a command as a variable: FILE_CORE_NAME="$(/usr/bin/env basename $(/...
Kevin Huntly's user avatar
0 votes
1 answer
76 views

File backed, key value store implemented with posix utilities

I imagine this is a pretty common thing to do. Which posix utility for reads, which for writes? What are the most common file formats to do this with? Is inplace modification possible? My first ...
Tom Huntington's user avatar
-2 votes
1 answer
225 views

Identifying Linux distribution from screenshot

A friend is asking me to help him out with this old linux box that he has which i believe it like over 15 years old. He only sent me this screenshot so I don't know much about it yet until i meet with ...
Singleton's user avatar
0 votes
1 answer
76 views

How to pass the standard input of a shell script to a background command

In a shell script, I am trying to start a background command that has the same stdin as that of the shell script. #!/bin/sh # ... the-program & However, the-program above will not have access to ...
Flux's user avatar
  • 2,770
-3 votes
1 answer
116 views

What happens if you put /dev/urandom into a shell script and run it?

I want to know what happens when you run the contents of /dev/urandom as a shell script. I know when you cat it into a terminal it will set off a bunch of random things in the terminal environment. ...
AcinonX's user avatar
2 votes
2 answers
112 views

"set editing-mode vi" v/s "set -o vi" what is the difference?

On multiple forums I have come across adding set -o vi to my .bashrc file. Today I saw the option of adding set editing-mode vi to .inputrc. I googled and both appear to do the same thing, are there ...
Ishaan Kapoor's user avatar
7 votes
5 answers
2k views

For loop through servers with custom ports (for i in "user1@server1 -p 12345" "user2@server2 -p 54321" ...; do)

I'm trying to run a command on a series of servers via ssh. I have recently changed ssh ports to avoid Internet scanners, but it broke my script. Does anyone know "an easy way" to specify ...
Daniel Krajnik's user avatar
9 votes
1 answer
931 views

GNU Coreutils `\time --version` and `/bin/true --version` work but `\true --version` does not?

$ \time --version time (GNU Time) UNKNOWN Copyright (C) 2018 Free Software Foundation, Inc. ... $ /bin/true --version true (GNU coreutils) 8.32 Copyright (C) 2020 Free Software Foundation, Inc. ... $...
charmoniumQ's user avatar
0 votes
0 answers
50 views

Is there a way to not exit a shell if jobs are stopped/suspended?

If one types exit and a job is stopped/suspended, the shell will print a warning message instead of exiting. 1: some_command & [1] 4018347 2: exit zsh: you have suspended jobs. But if one types ...
John Gordon's user avatar
1 vote
0 answers
53 views

SH script fails when something already exists [duplicate]

I have a problem with my SH script, I'm writing a SH script that automates the installation of OpenStack Keystone, and also uses a small configuration file, everything works fine but due to a syntax ...
Steforgame 910's user avatar
1 vote
0 answers
21 views

How to enable sh emulation mode only when using zsh interactively

When using zsh interactively, I would like it to emulate the behavior of sh as much as possible. I have tried adding emulate sh to the end of ~/.zshrc, but since I am using zsh plugins that rely on ...
Flux's user avatar
  • 2,770
4 votes
3 answers
459 views

Safely save and restore environment variables

I have a script that parses a rudimentary .env file and exports its contents as environment variables, before taking further action: set -eu test -f .env && load_dotenv exec ./foobar x y z &...
shadowtalker's user avatar
  • 1,278
3 votes
1 answer
432 views

How to exclude swapfile from rsync backup?

I'm trying to write a simple script that would back up my system files. Here's what I wrote so far: #!/usr/bin/sh if [ $UID != 0 ]; then echo "Please run me as root" exit 1; ...
Heather7283's user avatar
0 votes
1 answer
59 views

Is there any way to enable ansi colors in journalctl logs?

foo.py prints ansi colored output in my terminal Now if I execute foo.pyin a systemd unit and journalctl --all -u foo.service --output cat -f all output is monochrome. How can I journalctl systemd ...
jjk's user avatar
  • 399
0 votes
1 answer
561 views

Removing GitHub tools on termux?

I don't know if i can ask this question here or not. I have cloned some tools from GitHub on my termux. Then i ran the bash file "install.sh" that was a customized login with password tool. ...
Sina Vasmas's user avatar
-1 votes
1 answer
129 views

Handling user input of * with case in shell script

i am creating a simple calculator in bash. the user can enter operators "+", "-", "/", and "*". however, when the user inputs * as an operator, it goes to the ...
critter333's user avatar
0 votes
2 answers
61 views

Nesting quotes in shell

I want to execute a command which looks like $ sh -c 'exec python -c "print('$1$2MyString')"' with the desired result '$1$2MyString'. However, when I execute the command, I get Traceback (...
johnc's user avatar
  • 3

1
2 3 4 5
240