Questions tagged [bash]

Questions specific to GNU’s Bourne Again SHell, as opposed to other Bourne/POSIX shells. For questions about Unix shells in general, use the /shell tag instead. For shell scripts with errors/syntax errors, please check them with the shellcheck program (or in the web shellcheck server at https://shellcheck.net) before posting here.

Filter by
Sorted by
Tagged with
0 votes
1 answer
10 views

Change prompt colour inside midnight commander?

I use mc on CentOS9. It has its own prompt on the bottom under the panels. I dont know if it is a separate bash or some sort of emulation, but it has default colour while "normal" prompt is ...
59 votes
5 answers
38k views

View a range of bash history

The history command lists out all the history for the current session. Like: 1 ls 2 cd /root 3 mkdir something 4 cd something 5 touch afile 6 ls 7 cd .. 8 rm something/afile 9 cd .. 10 ls 11 history ...
2 votes
2 answers
26 views

Bash script segmentation fault

My assignment is to write a bash script that reads a directory and returns the file type of each file within, including all subdirectories. Using the find command is not allowed. I've tried to ...
2 votes
2 answers
164 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 ...
0 votes
2 answers
41 views

Replicating floating point arithmetic WITHOUT bc utility

I'm needing to write a script on some embedded Linux systems that don't have bc installed on them and won't be able to have it installed. The script I'm writing is essentially a monitoring script that ...
1 vote
2 answers
22 views

Remove files except latest one by numeric order

I am trying to remove files within a bash script. I can list the latest file with : ls | grep core | tail -n 1 and rename it like "keep-core-2994-xyz.bin", then remove the rest with: rm -f ...
1 vote
2 answers
100 views

unix pass - passing passphrase with the usage of PASSWORD_STORE_GPG_OPTS

Here's info on the pass: https://www.passwordstore.org My key point is, that I would like to pass the passphrase key at the command line. However, the topic and solutions related to this question that ...
0 votes
0 answers
10 views

bash process icon changed since I ran celeste with it

I set a menu entry for launching celeste via bash and now the bash process in the gnome system monitor has celeste's icon even though I already closed the game. Launching another app this way or ...
-2 votes
4 answers
105 views

sed or awk: replace only the n-th occurence of a string

How to write a sed (or awk, or both) which will take the following: echo '1 aa 2 2 3 bb 5 bb 2 5' | sed/awk ... And only replace the n-th occurrence of a string or word? For example the 3rd ...
3 votes
4 answers
37k views

create XML file using bash script

I want create simple xml file using bash script ( not with dom ) but when I set value in the line then echo print the $lorem word and not the val lorem=LOL echo '<root><foo a="b">$...
0 votes
0 answers
13 views

I am trying to unpack multiple tar folders in a directory and want to extract 'fastq' type files in the folder using a bash script. Below is my code; [closed]

Trying to unpack multiple folders to a directory, the folders name start with a common prefix, 'ABX-'followed by unique ids. I would like to unpack them with their names and copy them to a unique ...
2 votes
7 answers
272 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 ...
-1 votes
0 answers
7 views

How to setup email alerts on centos when openconnect user connect

My current setup i have ocserv openconnect and postfix server running on centos 8 I wan get email alert when openconnect VPN user connected or disconnect .
0 votes
1 answer
199 views

Why do trap sometimes ignore signals?

I have the following script #! /usr/bin/bash trap "{ echo bye ;}" SIGINT while : do echo "Hello" done When I press Ctrl-C the while loop is not stopped and echo ...
2 votes
1 answer
1k views

reading multiple files in while loop

I have a list of .gz files,like: abc-1.1.0-abc.tar.gz abc-1.2.3-hfc.tar.gz hfg-1.8.9-jdh.tar.gz Content of file_name: abcd_name_fb hsgdh_name_cd in my scipt, i'm capturing the strings '1.1.0,1.2.3,...
-5 votes
1 answer
52 views

What will this command output?

Can someone please explain in detail what the following bash command will output: for i in $(du -kx / | tr -s "\t"""| cut -d""-f2); do echo $i | rev | cut -d"/"-...
1 vote
2 answers
1k views

Trying to run .sh script from curl

I am having trouble running a shell script. So for context, I am using bash <(curl -s -L https://test.com/detect.sh) --argument1=true When I run this command in my Ubuntu environment, it works ...
4 votes
2 answers
13k views

Script with curl works manually but not in cron job

My script (status.sh) is: #!/bin/bash SITE=http://www.example.org/ STATUS=$(/usr/bin/curl -s -o /dev/null -I -w "%{http_code}" $SITE) if [ $STATUS -eq 200 ] then echo $STATUS >> /home/myuser/...
1 vote
1 answer
30 views

iterating though files in extracted directories and running an exe against the file with parameters

Ok, so here is what I am trying to do - I have a bunch of archives that are named: newnslog.0.tar.gz newnslog.1.tar.gz newnslog.2.tar.gz newnslog.3.tar.gz newnslog.4.tar.gz . . . once each is ...
0 votes
1 answer
28 views

Compare a file with stdout and print out not match line

Compare file.txt cat file.txt apache2 php7.4 mysql-server to the output of dpkg --get-selections Any package that are not matched the content of file.txt, paste them as the argument of "apt ...
0 votes
2 answers
33 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....
1 vote
1 answer
40 views

cannot figure out why the file will not copy

I am trying to write a program which i can reuse for copying content into multiple directories. But for the life of it i cannot figure out why the program does not work and is throwing this error. I ...
0 votes
0 answers
17 views

How can I redirect functions from a sourced file to individual scripts?

First I tried grepping the file using the matching only option and adjust from there; # REGEX function () { # ((\w|ç|Ç|ñ|Ñ)+\s+\(\)\s+\{\n) blahblah # (.*\n)+ } ...
16 votes
7 answers
4k views

Echo with obfuscation

I need to print some variables to the screen but I need to preferebly obfuscate the first few characters and I was wondering if there was an echo command in bash that can obfuscate the first ...
0 votes
0 answers
16 views

Arrange menu horizontally/detect arrow keys

I want to make a small game using bash script, The game, at the beginning provides 4 options for users to choose by using the four arrow keys such left, right, down, up. ex) 1) Join 2) Sign in 3) ...
0 votes
0 answers
15 views

shared library not found even if "export LD_LIBRARY_PATH" is set

Here comes a strange question. I have a QT App and it requires some libraries. Normally, the following bash script works: #!/bin/bash export LD_LIBRARY_PATH="./libs" export QT_DEBUG_PLUGINS=...
0 votes
1 answer
23 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 --...
1 vote
1 answer
21 views

How can I use the terminal and track what is being changed?

I was wondering if it's possible to use the CLI to track the changes I am making in an app launched through the CLI. For example: Launch CLI. Enter gnome-control-center. Make random changes in the ...
0 votes
2 answers
57 views

Rename files in any deep subfolder like the parent folder and move after to a central folder

I have a problem where I need to rename just certain files after the parent folder and afterwards move these to a central folder. Is there a way to do this? I would like to run this on a Synology NAS. ...
1 vote
2 answers
523 views

How to set `$CHROME_EXECUTABLE` in WSL2 for windows chrome

I'm trying to use the Windows chrome executable through WSL2 (for reference, Flutter looks at $CHROME_EXECUTABLE to launch web apps in chrome). In my bashrc I have the following: export ...
1 vote
2 answers
41 views

how to compare all files inside ONE directory in bash?

example given: dir1/ file1 file2 file3 file4 how do you compare file1-file2, file1-file3, file1-file4 then file2->file3, file2->file4 and so on. In this case the name is file_number, but ...
1 vote
0 answers
34 views

How to run input (x|grep y) in command

lets say when I execute command and then grep it for a specific output. for example: man cat|grep "Written" This gives the name of the authors. My problem is I want to do this via read. here ...
2 votes
1 answer
2k views

Bash script to sort files into alphabetical folders

I try to organize my files and my folders by a script. It creates the folder with the first letter of my file and moves it there. For the very first time, the script does the job, but if I create new ...
3 votes
5 answers
266 views

Bash: sed or awk rewrite of numerical sequence

How to write a sed (or awk, or both) which will rewrite the following: echo 'v100 v201 v102 v300 v301 v500 v999 v301' | sed/awk ... to this output: v1 v2 v3 v4 v5 v6 v7 v5 i.e. each subsequent vx ...
16 votes
4 answers
20k views

What's the difference between Ctrl-Z and kill -STOP?

When I run a command (make on a large project) from the shell, I can type CtrlZ to stop the process and return to the shell. Subsequently, I can run fg to continue the process. I'm trying to write a ...
2 votes
3 answers
668 views

How to list backup files missing corresponding real files?

I accidentally deleted some files spread across my home directory, but I do not know exactly which ones were removed. How can I get a list of all backup files missing their corresponding file? (...
3 votes
6 answers
478 views

Convert the first letter of all "."-separated parts of a filename to uppercase except for the last one in Mac Bash

I want to change the filename in the Mac Bash to initial capital after every dot/period, except for the filename extension. Input string example: one.two.three.four.txt Desired output: One.Two.Three....
0 votes
0 answers
29 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=$(...
46 votes
11 answers
155k views

Use config file for my shell script

I need to create a config file for my own script: Here is an example: script: #!/bin/bash source /home/myuser/test/config echo "Name=$nam" >&2 echo "Surname=$sur" >&2 ...
1 vote
1 answer
21 views

How to sync two folders with the same file names but different extensions

Is there a means of using rsync to sync two folders? I would like to shoot photos in JPG and RAW. Since viewing JPGs is much quicker than opening up RAWs, I'd like to do culling in the JPG folder and ...
1 vote
2 answers
700 views

Prevent sourcing a bash script, in the script itself

At the top of a bash script, I have this: if [[ "$npm_registry_override" != "yes" ]]; then echo "refusing to source npm.sh script because env is not set." exit 0; fi the problem is that when I ...
15 votes
5 answers
6k views

Can I select only one result from a bash glob?

I'm trying to write a script for work to automate some reporting on an output. The Log files are (currently, it's being 'standardise' in the future) stored in this sort of path structure: /<...
4 votes
0 answers
81 views

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

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

Periodically transfer files from two remote servers to single host using shell script

I have two remote data acquisition machines that are continuously writing data to their own local data.txt files. The remote machines begin acquiring data and appending their data.txt with new data ...
185 votes
2 answers
234k views

How to suspend and resume processes

In the bash terminal I can hit Control+Z to suspend any running process... then I can type fg to resume the process. Is it possible to suspend a process if I only have it's PID? And if so, what ...
0 votes
2 answers
31 views

bash: determining whether a variable specifically exists in the environment?

In bash, I know that there are a few ways to check whether a given variable is defined and contains a value. However, I want to check whether a given variable exists in the environment, and not as ...
0 votes
0 answers
34 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 ...
1 vote
1 answer
61 views

GNU parset is not working in a script but works in terminal

I ran into a strange problem.I am running this example from this https://www.gnu.org/software/parallel/parset.html. But it is not working inside the script file. parset myarray seq 3 ::: 4 5 6 echo &...
0 votes
0 answers
8 views

Adding full path to bash print ubuntu 22.04 [duplicate]

ubuntu 22.04 bash shell I am experimenting with the bash prompt. My objective is to display the full path as part of my command prompt (by adding the PS1 statement to my .bashrc). From terminal, I ...
0 votes
2 answers
3k views

Running JAVA in Cygwin through bash script

I've been encountering a problem with cygwin where I cannot run a jar file with an error that the file cannot be found. If it were easier i would "translate" the java source in bash, but ...

1
2 3 4 5
481