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
0 answers
69 views

eval a string which is the pathname of an executable file: "No such file or directory"

I am trying to run the community edition of SonarQube downloaded from https://www.sonarqube.org/downloads/. When I extract the downloaded zip file, I step inside $ cd sonarqube-9.4.0.54424/bin/linux-...
user avatar
  • 90.7k
1 vote
2 answers
53 views

.sh file does not execute all commands

I wrote a .sh file that only has a series of linux commands to automatically download all of my required files, packages and software should I need to do an OS wipe. This is what it looks like: sudo ...
user avatar
  • 143
0 votes
3 answers
158 views

Parsing simple JSON without grep -oP possibility

Here is my JSON: {"login":"WG1118412764OA","password":"9Hv1zd74nKhYovZa"} I have very basic grep, no Python, no Perl, and no jq obviously, just awk and sed. ...
user avatar
  • 35
-1 votes
1 answer
48 views

`unexpected end of file` after a while loop [closed]

The entirety of my Openbox autostart file is as follows: # Compositor picom & # Korean input ibus-daemon -dr & # Screensaver xscreensaver -no-splash & # Wallpaper while true; do ...
user avatar
  • 99
0 votes
0 answers
57 views

grep and extract from .log file and paste as shell command in shell

I have a list of files in a directory with extension .gz and for that same list I need to grep from final.log and get the same file name.gz.DONE name by using grep and need to search for the entire ...
user avatar
11 votes
6 answers
2k views

How to XOR two expressions of `test`?

I need to check that a directory (let's call it dir) contains one of two files (let's call them filea and fileb), but neither none nor both. The ideal solution would be to use a XOR operation between ...
user avatar
  • 828
2 votes
1 answer
106 views

Get specific file for every week using ls command

Could someone help me to get the file for every week using ls command? ls -t {path} | grep -e "-1700" | head -30 | sort -r With this ls command, I got below mentioned output 2022.05.30-1700 ...
user avatar
1 vote
1 answer
38 views

Retrieve last command when Chaining

When chaining commands in zsh using ;, && and ||, how can I access the previous command in chain (the command that is being executed before)? Example: rm foo ; echo ... In place of the dots, ...
user avatar
  • 13
2 votes
1 answer
77 views

run a command with double quote in new window in Alacritty

I can run gnome-terminal -- journalctl --since "10min ago" -f What is the equivalent of this command for alacitty. I tried alacritty -e "journalctl --since \"10min ago\" -f&...
user avatar
  • 1,329
1 vote
0 answers
32 views

whoami command fails after running /bin/su

I have a system with an init script that launches multiple applications, each under it's right user and group. The init script checks the home directory of each user and looks for the application init ...
user avatar
0 votes
0 answers
40 views

Simple way to delete files absolutely [duplicate]

I want to actually delete files in linux, as opposed to just erasing the representation of a file, with the command rm, for example, actually deleting the file literally, and as a basic good security ...
user avatar
0 votes
3 answers
53 views

How to get basename from each line in a file with Bash

I have a file with lines: file1 ./filled/Event_repeatFILLED.svelte ./dir2/Miscellaneous_servicesFILLED.svelte ./outline/Line_weightFILLED.svelte ./two-tone/ArchitectureFILLED.svelte ...many more lines ...
user avatar
  • 603
2 votes
1 answer
128 views

How to find keywords in multiple files which often appear together?

I want to find keywords, which often occur in relation to each other. Example A directory contains markdown files, each with some keywords on the last line: $ tail -n 1 file1.md #doctor #donkey #...
user avatar
0 votes
1 answer
33 views

Share or access existing shell session

Is there a way to access or create a shell in another user session? I have a user doing their things on a DE (like KDE) and I'm connected as root on the computer through ssh. Is there a way to take ...
user avatar
  • 25
1 vote
0 answers
70 views

unexpected EOF while looking for matching

I am getting line 0: unexpected EOF while looking for matching `"' error while running docker exec -it cassandra-test bash -c "cqlsh -k KEYSPACE -u USER -p PASS -e \"COPY tablename TO ...
user avatar
0 votes
3 answers
79 views

What is the fastest way of copying long paths for the cp command?

I'm controlling a Linux based NAS through SSH on a Windows computer. What I'm trying to do is use the cp -al command to rapidly copy folders from one directory to another, hardlinking all the files ...
user avatar
0 votes
2 answers
47 views

Print output of httpie command, then pipe to grep

how can I print output of httpie request then pipe to grep to check if request has succeeded or failed? http --print=hb POST http://localhost:8080 | grep -c "HTTP/1.1 200" && echo &...
user avatar
0 votes
0 answers
38 views

How to get file names, replace - with a space and insert in a file with shell/bash

I'm creating Svelte component files for SVG icons. I have many SVG files in a dir: ab-testing.svg abacus.svg abjad-arabic.svg abjad-hebrew.svg abugida-devanagari.svg abugida-thai.svg access-point-...
user avatar
  • 603
0 votes
1 answer
63 views

Is it possible to replace a shell like dash?

I'm working on building my own Linux distribution based off Debian. I am curious if it is possible to completely remove dash and replace it with as shell like fish or elvish. I am aware that you would ...
user avatar
  • 1
0 votes
3 answers
34 views

How to use sh script to send hex data to /dev/ttyUSB0?

I'm working with a paired down embedded Linux installation that does not support bash, only sh across a ssh terminal. I need to send hex data to a connected USB device /dev/ttyUSB0. I'm able to do ...
user avatar
  • 235
0 votes
2 answers
56 views

How to list files with only name and size

I would like to list the content of a directory, 1 line per entry, with only the files names and the files sizes. ls -l shows too much information. ls -1 -s doesn't show a file's size but its ...
user avatar
  • 1
1 vote
1 answer
38 views

Using move command to move all files and subdirectories with find

I have a folder /home/storage/aggregate_data with many sub-folders which in turn contain many files and sub-folders. I want to copy all the files older than 90 days within the folder /home/storage/...
user avatar
0 votes
2 answers
31 views

ZSh script to batch process filenames containing spaces and substitute extension

Is there a zsh script that can convert a directory files in one music format and be converted into Ogg opus format. The filenames have spaces in their names. For example, a directory contains 10 ...
user avatar
  • 101
1 vote
0 answers
30 views

Redirecting STDOUT to STDERR 1>&2 with sh [duplicate]

I am having a hard time understanding the difference between the order of 1>&2 and >. For example, I have file and file and don't have fie. Then diff fie file2 gives me error and I try ...
user avatar
  • 125
-1 votes
2 answers
41 views

How to use pipe with "sudo -ui"?

I have this command cat ~/.ssh/id_dsa.pub | ssh root@[my_server] "cat >> ~/.ssh/authorized_keys" How can I do the same thing but with sudo -iu user1 before the 2nd cat? That is, I ...
user avatar
  • 19
3 votes
3 answers
153 views

Every row of a file is converted to a new file

I have a file that contains four columns and 5000 rows. I want to make 5000 new files from this file so that each file has one row from the original file. Also, I want to name the new files according ...
user avatar
0 votes
0 answers
38 views

Questions on shell redirection [duplicate]

I am studying for my RHCSA and already have my Linux+ and I'm trying to better understand shell redirection beyond just understanding the basic use cases and I am trying to grasp it at a deeper ...
user avatar
  • 9
0 votes
0 answers
39 views

Upgrading Docker using APT deletes all images and containers

The following commands are used in a maintenance script in order to upgrade packages on the Ubuntu system: dpkg --configure -a DEBIAN_FRONTEND=noninteractive apt upgrade -yq -o Dpkg::Options::="--...
user avatar
  • 3,357
5 votes
3 answers
461 views

POSIX shell comment vs line continuation

Edit to clarify my question: POSIX says: If a <newline> follows the (unquoted) <backslash>, the shell shall interpret this as line continuation. The <backslash> and <newline> ...
user avatar
  • 51
0 votes
1 answer
20 views

Wired Xbox One Controller Shows in lsusb but stops detecting input in steam sometimes

After a reboot, my wired controller works with steam. There is a light on the controller that is on whenever this is working. Sometimes, however, the light randomly turns off and then input stops ...
user avatar
  • 101
0 votes
0 answers
50 views

systemd doesn't read environment variables required for script

I want to use borg backup and systemd timers to do my backups. I am using the script from borg backup website very slightly adjusted. You can see the original HERE and my script below: #!/bin/sh # ...
user avatar
  • 101
2 votes
1 answer
76 views

Why does paste command truncate one of the input files?

I have two files which contain only one column of numeric data each, and the same number of rows. When using paste, it does combine the rows from the two files into one row, but the text of the first ...
user avatar
  • 355
2 votes
2 answers
207 views

How to add a letter in front of file names in a dir when file names have digit(s) at the beginning

I have a bunch of SVG files in a dir. 0.svg 1.svg 2.svg ... 42Group.svg 500px.svg file1.svg file2.svg ... I'd like to add a letter A if a file name starts with a number. For example, I'd like to ...
user avatar
  • 603
0 votes
2 answers
40 views

What's a clean way to run a specific command C for each line L of a given file F and then move every L where C(L) ran unsuccesfully?

Say that https://example.nosuchtld https://example.net https://example.org https://example.willfail is the content of urls.txt. I want to run <command> <url> for every URL/line of urls....
user avatar
1 vote
1 answer
27 views

xdotool returning different output when executed from crontab [duplicate]

So I was making a script that monitors my app usage. It does so by running a cronjob every minute, and cronjob in question checks which window is focused on and increments its counter by 1. Other ...
user avatar
2 votes
8 answers
374 views

awk filter rows that only consist a single letter

I have a file (file1) that looks like this: ROW 1 AA 120 APFGHKDESFNNJFHGRIHJASFGNSKDHFIXXXXXX ROW 2 AA 234 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ROW 3 AA 122 XXXXXXXXXXXXXXXXXXXXX ROW 4 AA 89 ...
user avatar
  • 341
0 votes
3 answers
70 views

How to display a prompt and prevent execution against basic but dangerous commands like mv or rm

Objective Whenever I use mv (or commands of similar nature) I want my shell to prompt me something like "Hey, you used mv. Sorry but do it again using mv -i". I'd like to know the reasonable ...
user avatar
  • 391
0 votes
0 answers
30 views

Linux bash not working properlly [duplicate]

I am trying to run the following script on a OpenSuse machine: OUR_REPO=$(git branch | grep "*" | awk '{print $2}') THE_REPO_THAT_OURS_IS_BASED_ON="origin/$OUR_REPO" GIT_COMMIT=$(...
user avatar
  • 121
5 votes
0 answers
138 views

Ubuntu ls doesn't show all the files, but when I "ls filename", it shows up? [closed]

I am using PHP 7.3 to move some files around, in a larger app. The PHP 7 is running on Ubuntu 20.04.4 in a wsl2 container in Windows 10. On reading through other questions, it seems this is probably ...
user avatar
  • 51
0 votes
0 answers
40 views

Why is shell/terminal printing extra new line. What can be done to prevent it?

root@kali-linux:~# echo -ne "hi" hi root@kali-linux:~# echo "hi" hi root@kali-linux:~# I am using bash shell, xfce + i3wm + stterm in kali. On previous version of kali, there ...
user avatar
  • 113
1 vote
1 answer
40 views

Is there a commonly used environment variable or configuration setting for enabling widespread application verbosity?

Sometimes I write scripts where I want every called application to be verbose as can be for the sake of logging. This often includes typing --verbose quite a bit. Other than the -v and equivalent --...
user avatar
  • 465
-1 votes
1 answer
46 views

One master ksh file to call 2 ksh script files [duplicate]

I have 2 ksh (korn shell script) : file1.ksh and file2.ksh; and I want to have a master file ksh script that will call the 2 files; what's the code I have to put in my master file? Thanks
user avatar
  • 1
1 vote
0 answers
22 views

Counter-intuitive date command [duplicate]

I've been using date in a script in order to add one year to a specific date the following way: date '+%Y-%m-%d %H:%M:%S' -d "$DATE + 1 year" In this example, DATE looks like 2022-05-11 14:...
user avatar
1 vote
3 answers
328 views

What is a command? [closed]

Clear thinking and clear communication are facilitated when different terms are used to represent different concepts. This is particularly useful when the 2 concepts are very similar but different. We ...
user avatar
  • 336
0 votes
2 answers
127 views

echo file names containing 'a' and 'b' in either order [duplicate]

I have a list of files as follows: $ echo * add akfefg aka ab ba I want to echo file names containing both 'a' and 'b' in either order. I tried echo *[ab]*[ba]* aka ab ba and it also prints 'aka'. I'...
user avatar
  • 125
0 votes
2 answers
46 views

How to execute the next command in pipe only if previous have at least one result?

So, I have the following command $(docker container ls -a -q) | docker container stop to stop all my docker containers, which works great! Except when I've just wiped clean all of them: "docker ...
user avatar
0 votes
0 answers
44 views

Accessing environment variable set with "bash -c 'export FOO=BAR'"

I am trying to set environment variables from Bash as follow bash -c 'export FOO=BAR' but when I try to read the previously set variable using echo $FOO or bash -c 'echo $FOO' I can see that the ...
user avatar
  • 1
-2 votes
3 answers
67 views

How to remove forward slashes from file in unix shell using sed? [duplicate]

I have the following file : / /FUSE // Bank S.A / N.V /F I want to remove all forward slashes (/), so that the result looks like this: FUSE Bank S.A N.V F How to do so using sed? Ive tried using ...
user avatar
0 votes
1 answer
52 views

How can I get the size of a variable, string, or array in bytes?

For example, if I build an array: $ array1=($(find /etc -mindepth 1 -maxdepth 1 -type d)) $ echo ${#array[@]} 105 $ for each in ${array1[@]}; do echo $each ; done /etc/alternatives /etc/apache2 /etc/...
user avatar
0 votes
1 answer
81 views

Makefile subshell if condition

So I have the following code: .PHONY: test test: ifeq ($(grep -Fxq "substring" ./file && echo 1 || echo 0), 1) //do something else //do other thing endif The idea is simply ...
user avatar
  • 25