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
0 votes
1 answer
70 views

Quote characters work as commands that redirect to the standard input

I am a student and I am trying an excercise that involves assigning a word with quotes, double quotes and other symbols to a file name. The problem is that I am not getting the expected results. I am ...
Daniel's user avatar
  • 11
4 votes
1 answer
230 views

echo variable with letter immediately afterwards

p=$( power ) echo "Power now: ${p}W" prints Wower now: 357 This makes no sense. Surely this is a bug?
Richard Barraclough's user avatar
1 vote
2 answers
52 views

find files that start with a 6 digit number and matches number from the list

I have a big number of files around 185000, 99% of then start with a 6 digit number follow by underscore and other random symbols and random extensions 312095_ck_image-24-10-20-11-29-1.jpeg ...
Azat Usmanov's user avatar
1 vote
1 answer
74 views

Log a list of files and open them with VSCode CLI

I'm trying to create a macro on my shell. The operation I'm trying to automate is this one: Find all the files containing TEXT_TO_SEARCH, and open them with VSCODE I can do this with a one-liner $ ...
chc's user avatar
  • 113
0 votes
4 answers
116 views

How can I use parameter expansion together with command substitution?

I want to create 12 directories named after the months. So I tried using locale to get the month names, piping to tr to separate them with commas, then put braces around and passed to mkdir. But ...
teraspora's user avatar
  • 111
0 votes
3 answers
93 views

How do I change the extension of a long filename quickly?

original file: a really really long name with spaces.ext target file: the same name.new-ext command: mv *part of the name that'll give a unique answer.ext $(echo $(ls -l | grep -i *.ext | cut -d ' ' -...
kesarling He-Him's user avatar
1 vote
0 answers
85 views

Can't type the ^ character in the terminal but can use it in GUI applications

I use Manjaro, with i3, but the problem is also present with Plasma. For this message, I will call the ^ (caret) key, the key on the right on the p, where a "^" and "¨" is printed ...
mahaaaham's user avatar
0 votes
0 answers
18 views

How can I signal/force the parent shell to change directory? [duplicate]

I have this command called reclone, and this is my script: . load sudo -v extract sudo rm -rf /$organization/$repository cd /$organization git clone --depth 1 [email protected]:$organization/$...
Saeed Neamati's user avatar
0 votes
0 answers
21 views

How to copy terminal output to a file without using mouse [duplicate]

Say I have a bunch of text in the terminal. I can use my mouse/cursor to copy to clipboard but is there a way to copy the last X lines from the terminal to a separate file using a terminal command?
Alexander Mills's user avatar
-1 votes
3 answers
61 views

make new directories/folders based on contents of column

I need to make folders with data like the following. the folder should be named uniquely based on column 1 eg. A,B,C,D the contents of each folder should be the corresponding values in column 2 in ...
kaur's user avatar
  • 23
1 vote
1 answer
178 views

Bash - Check if the standard input contains anything

I know this question has been asked several times but it seems ineffective in my case. [[ ! -t 0 ]] = Does standard input contains anything? This command: echo 'Hello world' | [[ ! -t 0 ]] echo $? ...
Mario Palumbo's user avatar
4 votes
3 answers
520 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
36 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
28 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
56 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
84 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
41 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
177 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
2 votes
0 answers
94 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
136 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
2 answers
1k 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
5 votes
1 answer
225 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
125 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
2 answers
151 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
36 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
52 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
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
289 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
51 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
140 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
111 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,938
0 votes
0 answers
32 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
  • 609
4 votes
4 answers
333 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,938
2 votes
3 answers
802 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
114 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
370 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
  • 495
-1 votes
1 answer
70 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
78 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,901
0 votes
1 answer
100 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
137 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
85 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
233 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
146 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,938
-3 votes
1 answer
145 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
  • 111
2 votes
2 answers
177 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
949 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
1 vote
0 answers
228 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
62 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