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
39 views

Extract the RHS string by removing the whitespaces in between

dvc0723f380w2_high = (description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=dvc0723f380w2.us.com))(connect_data=(service_name=dvc0723f380w2_high.com))(security=(...
Meenal's user avatar
  • 3
0 votes
1 answer
62 views

fish 'Invalid redirection target' error

This command works well in Bash and Zsh: expac -H M "%011m\t%-20n\t%10d" $(comm -23 <(pacman -Qqen | sort) <({ pacman -Qqg xorg; expac -l '\n' '%E' base; } | sort -u)) | sort -n But ...
MHM's user avatar
  • 21
0 votes
1 answer
54 views

Is there a command that makes another command "in-place"?

I find myself trying to "edit" a file in-place quite a lot in my shell. Say, I want to remove all lines in words.txt that contain the letter e. Then, I would execute: $ grep -v e words.txt &...
Lorenz Leutgeb's user avatar
0 votes
0 answers
52 views

Bash complete not funcitoning as expected, capturing first result in COMPREPLY and then running all results as a command?

This is a bit of a tricky one, let me setup up what I'm doing here first to give you an idea of what I'm trying to accomplish. I'm reading from a set of ssh config files to get hosts and hostnames ...
Zarcona's user avatar
5 votes
3 answers
1k views

mv a bunch of files, but ask for each file

I would like to move a bunch of files on Linux like mv *.jpg /tmp/ But I would like to be asked for every single file, like mv --ask-me *.jpg /tmp/ do you want to move a.jpg? y/n y do you want to ...
Galdor's user avatar
  • 151
5 votes
3 answers
830 views

Open PDF from a command line and go back to the command line

I would like to open a PDF with evince from the command line and after the Evince window pops up, I want to go back to the terminal command with $ already waiting for the next command. Now if I run ...
Fibo Kowalsky's user avatar
-1 votes
2 answers
108 views

How to get complex regex to work in bash

The idea is to get a rudimentary check on input pattern for a url: $ ns='abc.def.com' $ reg_expr="\N*\.(\D{2}|\D{3})$" $ echo $reg_expr \N*\.(\D{2}|\D{3})$ $ [[ $ns =~ "$reg_expr" ]...
preetam's user avatar
  • 117
0 votes
1 answer
33 views

diff and comm are not finding difference between two env files

I have this env file 1.env contents: BARF_BAG=1 then another env file: 2.env contents: BARF_BAG=2 I run comm and diff on the files to see the difference: #!/usr/bin/env bash ( set -e; ...
Alexander Mills's user avatar
0 votes
1 answer
38 views

Group results using comm

Using comm I get results that look weird from this: comm -3 <(. "$first_env_file"; env) <(. "$second_env_file"; env) I get something like: AUTH_LP_ACCOUNT_ID=xxx1 ...
Alexander Mills's user avatar
0 votes
1 answer
145 views

trying to make my own shell handle ctrl+c properly

I am trying to understand how shells are set up so that the programs they are running receive the SIGINT when you press ctrl C but the shell doesn't, because when you are running bash, and run another ...
Alex028502's user avatar
0 votes
2 answers
65 views

how to make a subshell a "program"

I want to ignore all pre-existing env variables, and echo just one, like this: env -i <( export foo=bar; env ) and this would just print: foo=bar however, the construct of env -i <() ...
Alexander Mills's user avatar
0 votes
1 answer
72 views

diffing two .env files

I have two env files, let's say x.env and y.env, the order of the variables is different, but the content could be the same but likely different. Is there some tool I could use to diff the variables? ...
Alexander Mills's user avatar
1 vote
1 answer
165 views

zsh: check exit code of pipeline of commands

I have long pipeline of commands in zsh script: pv /dev/sda > sda.raw | sha256sum > sda.raw.sha256 | cut -c61-64 | read SHASUM how can I check inside an if statement, that all commands exited ...
Martin Vegter's user avatar
0 votes
0 answers
64 views

source command not loading all variables

I have file containing 1100 variables. Example, LOGPATH=/some/path VARIABLE2=someVALUE while running source /path/to/file.properties Only the first set number of variables are being loaded. Is there ...
debal's user avatar
  • 3,684
-1 votes
5 answers
178 views

How to mark things I download automatically executable?

I spend a lot of time downloading things that I am going to execute, without a doubt, after having downloaded them. Out of the 900-ish files in my download folder right now, roughly a third is stuff ...
Jean-Michaël Celerier's user avatar
0 votes
1 answer
78 views

"mv" command with asterisk character ("*") executed using "ssh"

I am inexperienced with Linux, but I am learning every day. I have this command. ssh admin@$host mv repo/environments/qa/* /repo Does this * character mean that EVERYTHING in the environments/qa ...
Chicken Sandwich No Pickles's user avatar
0 votes
1 answer
243 views

zsh: no such file or directory error even though the file exists [duplicate]

I'm getting an error while executing a binary that the binary cannot be found. I can see it using other commands. >> ls -alh ...
Igor's user avatar
  • 3
0 votes
2 answers
44 views

Copy (Rsync) only files from subirectories

I'd be really happy about some help. Lets imagine a snapshot of a directory structure: ../test1/test6/test62.txt ../test1/test6/test65.txt ../test1/test6/test67.txt ../test1/test6/test69.txt ../test1/...
Dr. Spongebob's user avatar
0 votes
3 answers
152 views

Figuring out the time until midnight, and output the result in a text file

How could I make lets say remaining time until tomorrow (midnight, also hours and minutes) and save that to a text file, like for example, "x hours and y minutes remaining until midnight" ...
Argo's user avatar
  • 3
0 votes
0 answers
66 views

Per-user cumulative CPU time across reboots

I have installed the process accounting package (acct) and recorded data. Using sa --print-seconds --user-summary | grep "$USER", I get the process account summary for my user: wjwrpoyob ...
wjwrpoyob's user avatar
  • 420
0 votes
2 answers
46 views

Replace last nonblank line with a command output

I have a .env file like PARAM1=val PARAM2=val I want to replace the last noblank line with another file content So far I have something like below: { (sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' local.env |...
gmtek's user avatar
  • 103
0 votes
0 answers
48 views

How to find out which clipboard manager my system uses?

I am not sure if the clipboard manager works as that shell interpreter in the sense we select one and only one to use in an interactive login shell (i.e., the terminal). If so, I wonder how to find ...
Rubem Pacelli's user avatar
1 vote
1 answer
29 views

How to redirect a command for a specific application

For example, the feh program can delete the currently viewed image, presumably using the rm command at some point. Let's say that instead of deleting the file, we want to run a trash script, say trash....
kleinbottle4's user avatar
1 vote
4 answers
155 views

Read nth column iteratively in two large files, cut and paste side by side to create new nth file

I have two files with around 100,000 space-separated columns in each. I want to extract each with column of the two files, write to a separate file and do command 2. Example for a file with two ...
AMS's user avatar
  • 37
1 vote
1 answer
845 views

What does mean `^(*.c|*.md)`

I am sorry if it is a potential obvious question, but I have no idea what ^() means in ls ^(*.c|*.md) On zsh, this argument expands to everything but *.c and *.md files. What is ^? What does mean ...
Rubem Pacelli's user avatar
-1 votes
2 answers
97 views

Copy file from Server A to Server B

I have requirement to copy files from Server A to Server B And then move the copied files Server A to Archive folder I have written the script, but it takes the directory name differently. Copying ...
user3792741's user avatar
0 votes
2 answers
34 views

How to extend piped command by contents of variable?

I would like to extend this line that calls /usr/bin/mplayer for recording an audio stream. The referring script record.sh could get called multiple times in parallel and I need to know in which ...
user146500's user avatar
4 votes
1 answer
26 views

Different behavior of `man` for root and user

Recently a user asked me for help and wrote: "Why does invoking man /bin/find display gibberish?" I answered that he was using man incorrectly by providing a path, that man was ...
Thagomizer's user avatar
0 votes
1 answer
25 views

Buffering follow + automatic pagination of output

I have a utility that continuously outputs live logs from a program. But it can be quite hard to read the logs lines as they scroll past me in the terminal. Ideally it should scroll to one full page, ...
David S.'s user avatar
  • 101
0 votes
1 answer
93 views

Is listing files with ls dangerous as stated on gnu.org documentation?

Is listing files with ls dangerous? If I run just ls command in a directory with unknown files, can something bad happen? Can you show me examples how running ls command is dangerous as stated in this ...
mhyynmmccs's user avatar
0 votes
1 answer
52 views

How to copy a directory structure and rename a subdirectory in the destination

Given this directory structure $ lsd --tree ...
mrt181's user avatar
  • 111
1 vote
2 answers
51 views

Shell one-liner for batch renaming music albums folders according to regexp – “zsh: missing identifier after `+'”

My music library consists of folders named after the following pattern : METAGENRE - Subgenre(s) - ARTIST - Album (year) I want to switch the year and album "tags" in the folders' names for ...
sylvainsab's user avatar
-1 votes
1 answer
90 views

How does a terminal produce accurate colors?

Background I am using terminals in various settings. Often the color output of programs is not correctly rendered on the screen. The internet is full of recipes for fixing the colors for specific ...
sjdh's user avatar
  • 231
1 vote
3 answers
139 views

How do I print out the file size in a shell script?

I'm trying to record the size of the compressed build file using Fastlane in my CICD pipeline. If I try this in the command line: du -h fileName.ipa | awk '{print $1}' it works fine. However, if I ...
KDBartleby's user avatar
0 votes
1 answer
134 views

zsh ignores zshrc most of the time (but not always)

So when I open a new terminal (kitty) my ~/.zshrc is sourced perfectly fine, oh-my-zsh works, plugins are loaded as well as the p10k theme. But if I, for example, simply run zsh (or tmux) I get a ...
beccasaurus's user avatar
0 votes
0 answers
34 views

CentOS 9 Stream SSH with PuTTy - multiline commands

I've been using CentOS versions 6, 7 and 8 for a long time. Finally, I started using CentOS 9 Stream version. It doesn't matter whether GNOME desktop version or server version (black screen), I ...
aycanuAydemir's user avatar
6 votes
3 answers
479 views

Pass result of find command as another command's multiple options

I have a CLI tool that can take an option with multiple values - The syntax is like this: CLI -I path/to/file1 -I path/to/file2 ... How can I pass the result of the find command to this CLI? For ...
hongweiy's user avatar
5 votes
3 answers
390 views

zsh -z test meaning of "+x"

I am new to zsh and have been a bash user for years. In an example zsh script I see a test: if [ ! -z ${ZSH_MOTD_CUSTOM+x} ]; then In bash I would expect: if [ ! -z "$ZSH_MOTD_CUSTOM" ]; ...
Que's user avatar
  • 53
1 vote
2 answers
71 views

Is there a native linux command other than awk/sed/perl/python that can toggle pipe output on or off?

For example, suppose I define a variable: DROP= And I have a loop: # highly compatible, streaming, # line-wise parser for embedded device # no awk or external dependency while IFS= read -r line; do ...
Chris's user avatar
  • 961
0 votes
0 answers
27 views

how to rename last part of multiple file in linux [duplicate]

I want to rename to files from below format to below format . How can i rename last part ? cheatsheetold1.gz.aux cheatsheetold2.gz.log cheatsheetold3.gz.out cheatsheetold4.gz.pdf cheatsheetold5.gz....
Anu's user avatar
  • 1
0 votes
1 answer
116 views

Is standard streams just variables?

When I run command, e.g. test -l --hello check: shell save the command to variables, $0="test", $1="-l", $2="--hello" and $3="check" shell execute ...
linuxer's user avatar
  • 27
-1 votes
2 answers
100 views

Why pipe keep sudo and redirection not? [duplicate]

Pipe (|) and redirections (<, <<, >, >>) both using standard streams (stdin, stdout, stderr), but although only pipe can keep sudo privileges, why? Works: sudo echo "hello" ...
linuxer's user avatar
  • 27
1 vote
1 answer
68 views

Converting a tcsh alias into zsh

I had a tcsh alias as follows: alias cdd 'cd `dirname \!*`' I use this to change the directory to the one containing a certain file. For instance, cdd /Users/myself/Document/Folder/File.pdf would ...
leparc's user avatar
  • 13
0 votes
1 answer
52 views

How do I determine the PID of the shell running a given pts/tty?

There are many ways to obtain the PTS associated with a given process - such as using the tty command or resolving /proc/self/fd/0 (assuming it's open and not redirected) - but what about the inverse? ...
Tenders McChiken's user avatar
0 votes
3 answers
88 views

Does `return 0` equal `true` (in sourced script to shell's environment)?

I am working on a highly portable script that users shall source to their shells, forcing me to use POSIX scripting. There are many useful functions in the script, one of them is special though, as ...
Vlastimil Burián's user avatar
0 votes
1 answer
53 views

mkfs.xfs completely ignoring "|more" redirect

trying to install gentoo linux and can't format the drive with xfs because when I run mkfs.xfs /dev/sda3 it throws an error and then displays help, but the help is so big that it takes up the entire ...
Zack's user avatar
  • 1
0 votes
1 answer
188 views

Check if two IP addresses are in a range

Using bash or perl on a minimal installed Linux, I am trying to validate two IP addresses if there are in a range. I came across a bash script that works well, but the fact that it prints all the IP ...
Bruce Malaudzi's user avatar
0 votes
2 answers
169 views

commands ran from Makefile are buffered, and don't print output imediately

when I run following command in shell, I see the rsync output real-time, as the files are being transfered: rsync --out-format="%n" --info=name1,del2 -rt /foo bar | sed '\@/mmc/@d' | grcat /...
Martin Vegter's user avatar
-2 votes
3 answers
114 views

sed: -e expression #1, char 101: unterminated `s' command

can someone suggest me what is going wrong here - sed -i "s|##CONNECTION_DETAILS##|${CONNECTION_DETAILS}|g" dep.yaml. The value of CONNECTION_DETAILS is in encoded form: ...
Meenal's user avatar
  • 3
0 votes
2 answers
60 views

Getting only used memory from free command every few seconds

It was explained e.g. here: Get separate used memory info from free -m command how to cut the output of free command. But I want to do this every few seconds and log it to a file. So I tried: free -g -...
Aleksander's user avatar