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
3 votes
2 answers
118 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
28 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
24 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,297
5 votes
3 answers
419 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
7 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
35 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
62 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
  • 353
2 votes
2 answers
183 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
  • 599
0 votes
1 answer
31 views

Copy/Paste files based on conditions

I need help writing some terminal commands (or a script) to automate a few tasks - moving .svg and .png files between folders. I am using Linux Mint Cinnamon 20.3 Lets say I have three folders full of ...
user avatar
0 votes
2 answers
36 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
22 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
306 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
  • 135
0 votes
3 answers
58 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
  • 357
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
122 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
36 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
0 votes
1 answer
35 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
  • 455
-1 votes
1 answer
40 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
322 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
115 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
  • 103
0 votes
2 answers
34 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
37 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
60 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
39 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
33 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
0 votes
1 answer
40 views

Count the number of words ends with specific character using Bash

Heys guys I wanted to count the number of words that end with 's' from this URL, https://matt.might.net/articles/what-cs-majors-should-know/ Here's what I did curl https://matt.might.net/articles/what-...
user avatar
1 vote
1 answer
46 views

Bash for every x files create sub folder and move files there

I am looking for an alternative dash command I can use as I am trying to execute the code from within python and due to the fact that the sub folder has 100's of files I am am trying to group into ...
user avatar
1 vote
3 answers
57 views

concatenate all the text files in all the sub folders into one giant text file

Ok so the situation is that I have an unknown number of sub-directories that all follow the same naming profile folder0, folder1, folder2, folder3 etc Now each folder will have 3 text files and these ...
user avatar
1 vote
0 answers
73 views

How can I execute a command in a shell script in a loop and in background mode?

In Restart mplayer stream process on loss of internet connection -> use while true an answer is given to restart an external command of a shell script - mplayer - after a connection loss. One ...
user avatar
0 votes
2 answers
45 views

How does ls [[:punct:]]* work?

I am learning bash. Currently, I have a file called _something.txt and when I use: ls [[:punct:]]* I get the following error: ls: invalid option -- 'V' What am I doing wrong?
user avatar
  • 1
0 votes
0 answers
28 views

Oneliner to archive, test the archive and remove source folder or stop if error

I've made my small shell function to un-compress the latest archive in a specific folder, then use it (code removed for sake of clarity), and then make an archive, test it and if everything is ok, ...
user avatar
0 votes
1 answer
23 views

stdin/stderr redirection, piping and color

I've seen a zillion permutations on this question but I think none is an exact duplicate. Can I copy only stderr (or eventually stderr and stdin) to a file, while keeping the colorized output on the ...
user avatar
2 votes
1 answer
137 views

replace character only when it's not inside curly braces (sed, awk, tr, ...)

I have a string called "desktops" that look like this: desktops="1 2 %{F#990000}3%{F-} 4 5 6 7 8 9 0" The 6 digits after the "#" represent an RGB color, so the 3rd ...
user avatar
0 votes
0 answers
24 views

How can I modify this script so that I can add multiple users by providing arguments?

How can I modify this script so that I can add multiple users by providing arguments (usernames) in the command line instead? I know at the very least I need to remove the read options. I don't want ...
user avatar
  • 1
0 votes
0 answers
15 views

Deluge bash script idea, do not start download with x or less peers at start of download, can someone point me in right research direction?

Not asking someone to do my work for me I know the golden rule of SO/SE but this shell script would be really helpful to me, basically if a download starts with x or less peers, it stops and deletes ...
user avatar
0 votes
3 answers
54 views

de-duplicate list but group parts of it

I am compiling some access rules from failed logins and after some piping I arrived at this: cat <<INPUT | sort -k 3,3 --unique Deny from 13.42.98.142 # demo Deny from 13.42.98.142 # test Deny ...
user avatar
0 votes
0 answers
38 views

exec terminate command by the space in single quotes

I have a simple bash script goes like #!/bin/bash set -e SPARK_CONF="--master ... \ ... --conf spark.driver.extraJavaOptions='-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps' \ --conf ....&...
user avatar
0 votes
2 answers
26 views

Is it possible to generate multiple complete commands with command substitution?

There are many commands that accept multiple parameters, like touch, ls and rm. So that I can use the construct {1..3} to generate multiple parameters for the command. For example: [root@192 ~]# touch ...
user avatar
0 votes
3 answers
46 views

Can I run a script on reboot once?

CentOS9 Keeping in mind this question: https://serverfault.com/questions/1099284/centos-how-to-keep-previous-service-state-on-reboot It seems that it is not possible to achieve what I need. Is that ...
user avatar
1 vote
2 answers
28 views

How to add n number of spaces at frontend

I have a text file : ABC.txt which contain below data I want to to n number of spaces at the frontend of my text file on every line A Apple a day keeps a doctor away B I like to play with Ball C I ...
user avatar
-1 votes
1 answer
55 views

How to remove only 1 line with a certain string

Hi i have a question i have searched everywhere but i cant find it. I want to use the sed command to remove a line containing a certain string. In the text file there are more lines with the same ...
user avatar
1 vote
0 answers
27 views

How to re-enable the `enable` command?

As part of a script to set up a restricted user, I ran the enable -n enable command. For testing purposes I would like to undo that command but I can't find any documentation on how to do so. I know ...
user avatar
  • 111
0 votes
1 answer
55 views

Run bash script in cronjob

i'm trying to automate a script using crontab. I've been searching for some information to help me, but haven't been successful so far. I created the script with the shebang and full paths. #!/bin/...
user avatar
  • 3
0 votes
1 answer
65 views

comparing 2 files unix

I have 2 scripts file.txt and file2.txt file1.txt |col1|col2| |name|mandatory| |age|mandatory| |address|mandatory| |email|mandatory| |country|not-mandatory| file2.txt |col1|col2| |name|gabrielle|...
user avatar
  • 3
0 votes
1 answer
29 views

While loop not outputting to a log file

I am making in-roads to getting a curl script to work as intended, working around some issue that requires pagination. My point is... the curl part works, BUT I can't get the output to log to a file. #...
user avatar
0 votes
1 answer
26 views

Remove particular characters in bash

I’ve got a script that pulls an image from a repo, manipulates it, and stores some info. I’m trying to figure out how to strip the tags that append these variables. A variable might be Nginx:23457@...
user avatar
16 votes
2 answers
2k views

Are there security consequences from not giving printf a format to use?

A well-formed printf usually has a format to use: $ var="Hello" $ printf '%s\n' "$var" Hello However, what could be the security implications of not providing a format? $ printf &...
user avatar
  • 38.8k
0 votes
0 answers
26 views

writing a private key from a variable to file

I have a scenario where I am exporting private key and writing it to a file. export CLI_KEY_FILE="-----BEGIN PRIVATE KEY----- 3MFPAZh1qa8XsLdlBBwRypZ8QxTzjdYe4trERoWoLMuaZWsAVRzTypCZG0/Hhfin ...
user avatar
  • 85
0 votes
0 answers
48 views

File list isn't displayng while using find with -maxdepth 1 to remove subfolders [closed]

I am trying to run the following code FILESIZE="+30M" find "$1" -maxdepth 1 -size "$FILESIZE" -type f -exec echo "put {}" \; in order to get a list of file ...
user avatar
  • 39

1
2 3 4 5
226