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.

Filter by
Sorted by
Tagged with
0
votes
0answers
5 views

Find-based mv renaming fails in a shellscript

I wanted to do a simple script to rename files, well parts of files. While the command works just fine from commandline: find . -type f -name "*old*" -exec bash -c 'mv "$0" "${0/old/new}"' {} \; 2>...
0
votes
1answer
15 views

Script to grep xml file and redirect output to files based off results

So i'm trying to write a simple script that'll parse a xml file and redirect output to a new file based off the name of the category it was found under. For example this is what the XML file looks ...
1
vote
1answer
15 views

ffmpeg merge multiple sets of 2 videos in for loop

I am still pretty new to linux and have been trying very hard at getting this right. Please help me to get this right. I am trying to merge 2 videos (1 from each folder) multiple times in like a ...
0
votes
2answers
44 views

What’s the difference between providing input to a command via an argument to that command and providing input through a shell redirection operator?

When I use my shell’s redirection operator to provide a (non-existent) filename to the grep command, the error message about that file not existing is displayed by my shell. But when I provide that ...
0
votes
1answer
37 views

How to optimize GNU parallel for this use?

I created this script out of boredom with the sole purpose of using/testing GNU parallel so I know it's not particularly useful or optimized, but I have a script that will calculate all prime numbers ...
0
votes
2answers
21 views

extra characters in bash prompt

I have been trying to customize my bash prompt below is my config #!bin/bash Nocolor="\[\033[0m\]" # Text Reset # Bold High Intensty BIBlack="\[\033[1;90m\]" # Black BIRed="\[\033[1;91m\]...
0
votes
0answers
6 views

KDE Dolphin Service Menu scripting difficulties

I'm trying to transfer (at least some most frequently used) Nautilus/Nemo Actions/Scripts to Dolphin Service Menu Actions, which is a challenging task for me with elementary level scripting skills. ...
2
votes
1answer
17 views

Script does not run commands in bluetoothctl

I wrote a small script to automate the connection of my bluetooth headphones to my linux machine. #!/bin/bash bluetoothctl wait ${!} connect XX:XX:XX:XX:XX:XX #headphone MAC address wait ${!} exit ...
1
vote
1answer
27 views

How to backup and restore the current display colors and formatting?

Is there a way to backup the current display color and formatting such that I can echo some custom color and then reset things back to the previous state? For example: echo -e '\e[31m'123; echo 456 ...
1
vote
2answers
54 views

How to ssh and run multiple commands wrapped in if else?

I wanted to capture some data from various servers using ssh and run some commands with some conditions. I don't want to do: if ssh $host test -f /file; then # If file exists var=$(ssh $host ...
2
votes
1answer
53 views

Can the script detect a difference between “bash somescript” and “bash -c 'source somescript'”?

Looking at the (prior) title, it has great chance to be marked as "duplicate". I have a script (test.sh) that does not take any arguments. I call it in following two ways : bash "test.sh" # ...
2
votes
1answer
59 views

script to shutdown server if no active users

I want to write a bash script that will run with cron every 5 minutes that will check if there's any active users logged in and if no active users are logged in, it will shutdown. I've come up with ...
0
votes
2answers
35 views

Bash: Run Command (with a specific pattern) only if another Command (with another specific pattern) has failed

I have a shell script that creates a function (in a bashscript file which is sourced by .bashrc) for each Markdown files to open it in the editor. Example: ls /home/nikhil/Notes/Studies Physics.md ...
0
votes
2answers
25 views

poll for the right output of a command

completely new to bash so any assistance is much appreciated. I'm looking for a script to do the following, its a pretty simple script but I cant seem to get it: I want to run a command, this command ...
-2
votes
1answer
55 views

Can I customize “command not found” bash message?

Title pretty much. I tried editing bash.bashrc, the command not found handle, but it did nothing really.
0
votes
0answers
18 views

Show ports in hexadecimal for netstat or ss command

I am trying to format the output of netstat or ss command in bash terminal. I need to convert the port numbers to hexadecimal. Currently they are shown in decimal by default. Is there any option in ...
1
vote
2answers
46 views

How to remove CRLF from awk $NF column

I'm not sure how to phrase the question as most of the answers are about removing \r\n from a file. I have a unique problem where compressed files are numbered randomly and in order to associate them ...
0
votes
2answers
47 views

System-wide aliases

I have my aliases set in my ~/.bash_aliases, it works like a charm in terminal. Howerver, it doesn't do the same with Application Finder Alt + F2 or Whisker Menu. Anybody know how to fix this? Thanks. ...
0
votes
2answers
43 views

Difference between subshell and if block

Is there any difference between: set -e; ./create-git-tag.sh || { echo 'Could not create git tag.' exit 1; } and set -e; if ! ./create-git-tag.sh; then echo 'Could not create git tag.' ...
0
votes
2answers
36 views

Compare date and timestamps

I am trying to compare two timestamps and if x is greater than y then do some action. I tried it with bash on my Linux machine but I get an error "invalid date" here is my code: #!/bin/bash x='2020....
0
votes
0answers
34 views

executing commands when network goes down or up

I'm trying to get the Network Manager dispatcher to run a script when the network interface comes up or goes down. I want to execute an espeak command when the connection goes up or goes down. I can ...
0
votes
2answers
63 views

How do I create multiple files names from list.txt in bash also change the text of that newly created file?

I want to create multiple files at a time using names from a file list.txt, as well as the text in each files. Suppose I have a list.txt containing some id. numbers, now I want to make separate files ...
3
votes
5answers
128 views

How do I create multiple files names from list.txt in bash?

I want to create multiple files at a time using names from a file list.txt, how can I do it? Sample list.txt: EOG090W002U EOG090W00C1 EOG090W00DC EOG090W00DE EOG090W00E5 EOG090W00HR EOG090W00MH ...
0
votes
2answers
60 views

bash scripting input from 3 files

The original data from which I've created these 3 files quota username bytes 20480000 user1@abx.com 896 30720000 user2@abx.com 3002766 20480000 user3@abx....
1
vote
1answer
27 views

bash bug - unexpected EOF while looking for matching `"' on tab completion

I know this question has been answered many times like here and here. But all of them had places where there was an extra erroneous quote. I am just running a simple awk script in this fashion: awk ...
0
votes
1answer
47 views

bash prompt wrapping to start of line

I was trying to add some color and the time to my PS1 prompt on Debian 10 in my ~/.bashrc file. It initially looks right, but if I type a line that's more than about 40 characters the cursor moves to ...
-1
votes
1answer
31 views

get full path to shared directory

I have done following #!/bin/bash PROJDIR="//$HOST/projects" cd $PROJDIR newscript exit 0 Purpose of the script is to enter in shared folder and trigger another script within it, but the script ...
0
votes
0answers
52 views

Script to compare 2 or more file and dump the difference as output

I have a file containing the following values on 3 different servers. Server a = file1.txt Server b = file2.txt Server c = file3.txt This is the sample the above file contains file1.txt RoleA is ...
0
votes
0answers
41 views

route add command does not work on bash script

I have some route add commands to run on Ubuntu. It works when I copy the command and paste it on the terminal. But I've tried to create a bash script which looks something like this #!/bin/bash ...
0
votes
1answer
44 views

Get exit code from command “exec” [duplicate]

How can I get the exit code from command exec ? This is the sample code. For the others commands it works but not for exec. exec "somethings" if [ $? == 0 ]; then echo -e "Done\n" exit 0 ...
0
votes
0answers
17 views

bash prepend date command to pipe output [duplicate]

I have a MQTT command that outputs me the power in watts of a device. I run this command and it continously outputs me the watts value and I pipe it through jq because it is json formatted. Later I ...
0
votes
1answer
44 views

Interacting with binary through stdin and stdout

The setup: I have an executable file, that I "cannot edit", since I don't have the source code. When I execute the program it reveals a game, where it hands me some numbers via stdout, for me to ...
0
votes
0answers
36 views

What is the definition of a string in Bash?

What is the definition of a string in Bash? Bash use the term "string" several places in its documentation, e.g. to document the =~ operator used for regular expression matching: An additional ...
0
votes
0answers
21 views

GNU `find` issue : `find -name` isn't recursive when pattern is found in current directory [duplicate]

I have a test tree that goes like this : user@host :~/test/ $ tree . └── 1st ├── 1st.json └── 2nd ├── 2nd.json └── 3rd └── 4th ├── 4th.json ...
0
votes
0answers
27 views

$SHELL in tmux is different than $SHELL in the shell that I launched it from

Been wrestling with this for a few hours and it’s driving me crazy. When I SSH into my machine at home, my default shell is zsh. I can confirm this with echo $SHELL, which outputs /usr/bin/zsh When I ...
0
votes
0answers
31 views

pipe script to bash and also use read

If I do this: $ { > sleep 1 > read -p "Press Enter to continue" > } I get the prompt after a second, as expected. Now, if I do this: $ echo 'sleep 1; read -p "Press Enter to continue";' | ...
0
votes
1answer
34 views

Wait for specific response, then execute next command

I have the following bash script: #!/bin/bash set -m ./cloud_sql_proxy -instances=[project-id]:[region]:[instance-id]=tcp:5432 -credential_file=serviceaccount.json & sleep 5 node app.js First, I ...
0
votes
0answers
24 views

Remove unwanted character from a variable

I've seen a few of these questions, and a few answers, but they only tells me how to echo the results to the screen, and often only refers to one character. I need to remove the chars ', and keep ...
0
votes
1answer
16 views

jq: globbing possible?

I have the following json output: { x0: { scores: { small, human readable }, payload: { huge data } } { x1: ... } { x2: ... } ... { xn: ... } What I would like to do is, when I finish generating ...
1
vote
1answer
47 views

Use bash when ksh is shell

I have access to several RHEL systems that use Active Directory for user accounts and a NFS mount for home directories. Our login shell is stored in Active Directory and is always /bin/ksh. I want ...
0
votes
1answer
36 views

dot (.) causing alias to break

I am trying to create an alias for the command - rsync -avh --omit-dir-times --delete --filter='protect .sync' /media/blueray/Data/_Work/ /media/blueray/Data/_CloudYandex/ The command I am using to ...
0
votes
1answer
75 views

Compare timestamps

I am trying to compare timestamp of the latest modified file towards current time and if the diff is more than two hours I am trying to print that out. How can this be done? The following command ...
0
votes
1answer
31 views

Bug: `watch &` won't work within a script

I had the following script to alert me when someone sends me mail: cd /var/mail watch -g ls && cat end ./alert end would be a blank file; when I am going home, I would modify the end file ...
0
votes
1answer
54 views

ambiguous redirect using curl

I have this: /dev/null <& curl --silent "$url" \ -H "Content-Type: application/json" \ -X POST \ -d "$(cat <<EOF {"state":"failure","context":"continuous-integration/jenkins","...
3
votes
3answers
92 views

Find exec sh: Shell variable not getting passed to subshell

Here is a simplified code that prints the name of Directory if it contains a Filename with same name as the parent directory and .md extension. FIND(){ find . -type d -exec sh -c ' for d ...
0
votes
1answer
32 views

Loop through .nc and .txt files simultaneously

I need to loop through all .nc and .txt files simultaneously, that are in current directory. For each loop the files .nc and .txt have exactly the same name, it is just that ending (.nc and .txt) that ...
0
votes
1answer
24 views

Append .txt file by cat inside the last exisiting line of another .txt file

I have a .txt file which I cat into another .txt file. The last line of the original file (final.txt) ends with "lats =" and then by applying cat, the numbers below "lats =" are added, as shown ...
-3
votes
1answer
27 views

Concat two vars to call third var

I am sorry if this has been answered before, I tried searching and was unable to locate any corresponding answers: $a="hello" $b="world" $helloworldtest="worked" echo "${a}${b}test" - prints Hello{...
0
votes
0answers
18 views

How to run script with nohup through sshpass

I want to pass a local script generated on the fly and it will trigger another script on my remote machine to running some commands for a long period of time. this is the command I have tried: cat &...
0
votes
2answers
55 views

if --help doesn't work in terminal

if --help doesn't work in terminal, why? Linux Mint 19.3 Cinnamon 64bit Shell: Bash