Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

-1
votes
1answer
19 views

script calling another script?

ive written a couple a couple of scripts. are they going to work indefinatly and will them eventually overload the CPU? firstly this is on a local nas that for some reason the manufacturer does not ...
0
votes
1answer
24 views

bash script split file names

I have the following bash script: #!/bin/bash for r in $(find . -name "*.fastq"); do cat <<EOF #qsub <<EOF #!/bin/bash -l #PBS -N $r EOF done Unfortunately, all filename get ...
2
votes
2answers
60 views

import environment variables in a bash script

I set some environment variables in a terminal, and then run my script. How can I pull in the variables in the script? I need to know their values. Simply referring to them as $MY_VAR1 doesn't work; ...
4
votes
2answers
277 views

The files with the extension bash and sh

I made some researches about the files with bash and sh extensions. Most of the people and resources say that if a file has bash extension, then it contains bash scripts. Likewise, the file with sh ...
1
vote
1answer
40 views

How can I source a base 64 encoded file in bash?

Is there a way to source a base64 encoded file in bash instead of doing this? cat $DIR/data/saves/$savegame | base64 --decode > $DIR/data/saves/$savegame.decoded . $DIR/data/saves/$savegame....
0
votes
1answer
30 views

Visible content of 2 variables in bash is the same, but the length is different

These 2 variables will have the same visible content x_sign1="aabbccdd_and_somthing_else" var1="...." [........] x_sign2=$(echo -n "${var1}${var2}${var3}" | shasum -a 256) echo $x_sign2 ...
0
votes
1answer
21 views

Maintaining several constants for several bash scripts

I have several individual bash scripts. They do different things, and are large (70-100 lines each). Thus I have kept them in separate files. But they are all related to a central problem and hence ...
0
votes
2answers
43 views

Bash array script, combine

I'm trying to write bash script, which will automatically read all file names in current and custom directories, then apply new created docker image' names to finded yml files via kubectl, then read ...
0
votes
1answer
21 views

How to implement returning to top level menu?

I have a complex menu driven program along the following lines: echo "Navigate through the following choices when you get the #? prompt: " options=("Action 1" "Action 2" ...) select $opt in "${...
1
vote
1answer
34 views

Generating a report from bash output

I am currently trying to write a script in Bash that can run a set of unit/integration tests. I have that part working, but what I need now is to be able to output a summary at the end. I have been ...
-1
votes
4answers
54 views

SQL operation on csv file using bash or shell

This is my input file 0164318,001449,001452,001922 0164318,001456,001457,001922 0842179,002115,002118,001485 0846354,001512,001513,001590 0841422,001221,001224,001860 0841422,001227,...
0
votes
1answer
32 views

Bash script to move through folders, unzip, and move files up one directory

I have a group of folders that all have zip files in them that may contain 1 or 2 files in them each in a new folder. (see diagram below) I want to point the script at the top level directory and ...
2
votes
1answer
50 views

Cleanup Script for macOS

I have a bunch of shared Mac workstations with dozens of users. These users constantly leave large files on their desktop and in the trash, which eventually fills up the local hard drive. I want to ...
0
votes
1answer
28 views

Renaming Multiple files in different directories [duplicate]

I have about 5TB of data stored on Synology NAS servers with a DSM of 6.1+, so bash should be available for use on these systems. The issue is that we are currently archiving this data to external ...
0
votes
1answer
48 views

Bad substitution when running from cron

I have a function (notify_dba) that with two string args, a header and a body. (correction) Works well from shell prompt, but not in cron Err, doesn't work in either shell or cron (but should...?): ...
0
votes
0answers
23 views

How can I regex match-and-replace _all_ on-screen text?

I need a way to replace an on-screen pattern with another string, regardless of what places that text on the screen. Maybe I can live without user input being replaced, but anything that comes from ...
-2
votes
0answers
46 views

Whenever I open shell it print command not found [on hold]

Whenever I open a new tab or new window I see the following error in the console bash: 4e3291fa48f43adebb522c3c91f49c3120d927525994a34052bee83fb15b55f9: command not found bash: ...
-1
votes
0answers
27 views

How to capture a terminal command and replace by another one?

I want to redirect the user's command line, to copy another folder when they tried to git clone content from a specific folder. For example: git clone https://github.com/delivery.git john_copy I ...
1
vote
2answers
43 views

Copy a folder overwriting ONLY smaller files in destination

I have tons of PDFs in multiple sub-folders in /home/user/original that I have compressed using ghostscript pdfwrite in /home/user/compressed. ghostscript has done a great job at compressing about 90% ...
3
votes
1answer
45 views

How to run script at start when everything is up and running?

I have a PC for routing purposes, it has 2 network interfaces and runs Debian. I want to add a sound to it, to signal that it is booted and okay. So I've created some /etc/init.s/beep-startup script, ...
0
votes
4answers
56 views

Get the command that generated piped data

I'd like to figure out a way to access a string describing the command that was run before the current command running. For example, if I run: ls | myscripthere I'd like to be able to know that the ...
0
votes
1answer
30 views

[1]+ Exit 125 nohup [on hold]

I am running the following command: nohup ./run_hyper_param_tuning.sh> ../../logs/hyper_model_15_b_Jan.txt 2>&1 & echo $! >save_pid.txt It has been always working but suddenly it ...
-3
votes
0answers
61 views

brute forcer tool in bash have problem [on hold]

i coded an tool with bash script for bruteforcing one of website accounts. my code is: #!/bin/bash clear old_IFS=$IFS IFS=$'\n' lines=$(wc -l passwd.txt | cut -d " " -f1) IFS=$old_IFS linesNum=${#...
1
vote
1answer
21 views

Can I create BASH function that will hold text block that can then be called for output to FILE and SCREEN to cut down on code block repetition [duplicate]

I have a BASH utility that outputs measurements to screen live as it runs and writes the result to file at the same time. I am having to repeat the same code twice (see below). Once to write to ...
0
votes
5answers
78 views

How to separate each line of text by comma and put them in an array?

I have a text file and I want to create an array out of it like this: array=["line1","line2",...]. Here are the first lines of my text: Hamlet William Shakespeare Edited Barbara B Mowat Paul ...
6
votes
1answer
312 views

Is there a difference between cmd_drain < <(cmd_src) and cmd_drain <<< “$(cmd_src)”?

The cmd | read -r var1 var2 construct famously does not work in bash because the read command is executed in a subshell due to piping. I used to use read -r var1 var2 <<< "$(cmd)" to get ...
0
votes
3answers
29 views

How to escape parenthesis in bash rmdir?

I have a directory that has a name like 10.2 (14C92) i want to remove using rmdir -rf (to include their content). I am very new to the linux command line so i do know how to pass a space with \ but I ...
0
votes
0answers
20 views

Get output of server crash from server re-spawning script

I currently have Homebridge set up on my raspberry pi. When the pi boots, it starts a script which attempts to keep homebridge alive. I originally took the script from this answer which walks you ...
4
votes
2answers
328 views

Find only GUIDs in file - Bash

I have a file that might contain GUIDs (their canonical textual representation). I want to do an action for each GUID in the file. It might contain any number of GUIDs. I have already a file ready ...
10
votes
1answer
379 views

Usage of enclosing braces {} as arguments to commands and their options

Examples I've recently found examples of using pairs of enclosing braces {}, with nothing in between the opening and closing braces, as arguments to commands and even to their options: cat foo | ...
-6
votes
1answer
46 views

bash loop all files in directory, then loop lines of each file

I have urls1.txt urls2.txt urls3.txt And so on. How can I loop all files in this directory then loop each line of these files?
1
vote
2answers
36 views

Error while trying to compress pdf using ghostscript recursively via loop

I intend to compress a few thousand PDF files in a folder recursively. I tried with following loop: #!/bin/bash find "/home/user/original" -type f -name *.pdf | while read -r file do gs -sDEVICE=...
0
votes
1answer
64 views

BASH logic problem; difficulty testing one string variable with IF and OR

I have a string var1 which I am using in BASH. It can be three values var1=on var1=off or var1 can be equal to anything that is not on or off I wish to build an if statement in BASH that tests $...
1
vote
1answer
24 views

No nohup logs on remote server

I'm trying to start a proccess on remote server with ssh. I need to log stdout on target server (not the local one) Here is the script: sshpass -p mypwd ssh root@myserver.com nohup java -jar /tmp/...
0
votes
1answer
20 views

Reading multiple files and operating on stored Arrays

I have 2 text files "${LinkP}" and "${QuestionP}. I want to read these files and store each complete line in the respective array, IFS=$'\r\n' GLOBIGNORE='*' command eval "LinkA=($(cat "${LinkP}"))" ...
0
votes
3answers
54 views

How do I generate a sequence of numbers like this?

I am trying to generate a sequence of numbers where it adds 1 every other time, and 39999 every other time. Example of list which does what I want up to a million: 1 40000 40001 80000 80001 120000 ...
0
votes
0answers
27 views

After SSH not able to read the input from the keyboard and display on the screen

#!/bin/bash server=(*.*.*.*) echo "Connecting to IP : $server" ssh -i dotestnet root@${server} " echo "Present Working Directory : $pwd" echo "Deleting existing packages...." rm -rf ~/transactions rm -...
1
vote
1answer
25 views

Define variable using read from stdin of heredoc

I am trying to store Available and Total Memory into variables in a script file as follows, read -r Available Total <<EOT $(free -m | awk '/^Mem/{print $7; print $2;}') EOT $ echo $Total $ ...
2
votes
2answers
22 views

can bash show one array item id and value using `declare -p`?

$ str="a'\"b" $ declare -p str declare -- str="a'\"b" # see " was escaped, possibly other chars will too $ astr=("$str" "c") $ declare -p astr declare -ax astr='([0]="a'\''\"b" [1]="c")' so, is there ...
0
votes
3answers
40 views

Oneliner for outputting to file only if string is matched (bash)?

I am making a script where I curl a URL and output to a file like this: curl http://example.com/$1 > $1 Is there any way to make it dismiss anything that doesn't include, say <head>? I ...
1
vote
1answer
135 views

Bash prompt getting garbled when I browse history?

I have MacOS and .bash_profile content: export PS1="\[\e[0;31m$\]\[\e[m\] \[\e[0;32m\w\e[m\] : \]" as a result I have pwd printed in terminal like this: but when I press up and down arrows to use ...
0
votes
1answer
22 views

Bash: Error in assigning default value to a variable

Inside my bash script: This works: CWD="${1:-${PWD}}" But, if I replace it with: CWD="${1:=${PWD}}" I get the following error line #: $1: cannot assign in this way Why I can't assign to ${1}?
0
votes
1answer
68 views

How to write Bashrc with and without sudo for different use cases? [closed]

I'm searching through a ton of packages between a vm and host to see which package is causing text input issues for steam. I frequently need to check for and install packages on the guest machine and ...
0
votes
1answer
19 views

Running multiple commands using one file

I have a file with listed commands: first is the script name, like: get_1000g_r2_prevcf_snplist_e.pl and everything else is argument to the script. Here is a couple of lines in the major file which I ...
1
vote
0answers
23 views

Shell Scripting best practice to make sure script is not over utilizing memory or CPU [closed]

I have been writing shell scripts from long time but I never thought of optimizing script to make sure its not using more cpu or memory .. I am looking out for some suggestions or process with which I ...
0
votes
1answer
26 views

Merging PDF files with similar names

I have a folder populated with PDF files in this format: SI-T-xxxxxx.pdf SI-T-xxxxxx-sol.pdf SI-T-yyyyyy.pdf SI-T-yyyyyy-sol.pdf and so forth, with the middle part being digits. I want a way for ...
0
votes
3answers
43 views

How to use wildcard * with 'A long filename'?

I'm trying escape characters like \' but it doesn't work. $ cp 'A long filen* ./short_filename
0
votes
1answer
63 views

Remove file-name extension, if it exists

Very new to scripting. I have a directory containing some text files and some with text files that also contain an additional extension (.xfr) e.g. file1.txt, file2.txt.xfr, file3.txt, file4.txt.xfr. ...
1
vote
2answers
28 views

Speeding up repeated python calls (or, alternatively, porting a complex regex to sed)

I am an academic medical physicist. I do experiments that generate a fair amount of data, and they are expensive to run. My university has a backup system that consists of a robot tape library in a ...
1
vote
0answers
22 views

Correct way to quote variables for use in Bash backticks? [duplicate]

I have a script which I want to go over 4 sets of files PURO*.xml, PURR*.xml, SALO*.xml and SALR*.xml. for j in PUR SAL do mask=("${j}O*.xml" "${j}R*.xml") for k in 0 1 do ...