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.

2
votes
1answer
33 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
21 views

Renaming Multiple files in different directories

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
32 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
19 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
43 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
24 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 ...
0
votes
2answers
28 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
42 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
29 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 ...
-1
votes
0answers
47 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
73 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
305 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
28 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
324 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 ...
9
votes
1answer
362 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
34 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
63 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}"))" ...
-1
votes
0answers
55 views

Automate forcibly closing open files that have been deleted already by a misbehaving application [on hold]

On our Hadoop cluster, we have an application that opens and deletes files, but never closes those files. As this has a performance impact, we're now manually closing those deleted files by using gdb....
0
votes
3answers
53 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
24 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
134 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
66 views

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

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
18 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
27 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 ...
0
votes
1answer
34 views

Output string to log file, then pipe to function as argument

So I am trying to echo a string out to a log file and also pass that echo'd string over to a function along with other arguments as well. I can't seem to figure out how to do it or find any answers on ...
1
vote
1answer
35 views

Desktop Entry Requires “bash” in Exec Value

I recently began messing with Desktop Entries in order to run some scripts at Gnome startup. I've read through some freedesktop documentation, as well as this post on creating a startup script. I ...
1
vote
1answer
30 views

Login script that requires user to re-enter displayed random number string

I currently have a script that runs upon a user logging into a Linux server and at the end it prints [Terms of use agreement prints here] read -p "Agree and continue..." -nl -s However, most users ...
1
vote
2answers
35 views

bash: declare/typeset without assignment appears to fail

Using bash 4.3, there seems to be a discrepancy between the manual and actual behaviour: unset string # just to be sure declare string # $? is 0 afterwards declare -p string # fails, 'string: not ...
0
votes
1answer
37 views

Find, grep and then create table

I am trying to find all *.md at ${PWD}, then grep for lines beginning with title: and print it along with the absolute filepath -H and the line number of the pattern match -n, then I try to output the ...
1
vote
2answers
31 views

bash remove duplicate lines from txt files in folder

I have this command to remove duplicate lines from a file and save the unique lines in a new file uniq telphone.txt output.txt However Im trying to find a command that scans all .txt files in the ...
-2
votes
0answers
44 views

Calculate percentage from two date/time stamps bash

I have two files "DURATION.txt" and "ABCDURATION.txt" which contain ~900 records where DURATION.txt is the total runtime and "ABCDURATION.txt" is a portion of that total. What I need to do is ...
0
votes
1answer
28 views

bash: ucbps: command not found

How do I solve this? bash: ucbps: command not found [cbwlskbd@cbl06677app08 ~]$ Where to include the path for this? and how the paths are included
0
votes
2answers
26 views

Renaming part of name of all files in a directory tree if match

I have a directory tree like this . |-- players | |-- red_alice.plr | |-- red_bob.plr |-- resources | |-- red_cash.rsc | |-- red_food.rsc I want to go through all directories and rename any ...
0
votes
1answer
33 views

How can I check if the number of arguments passed into the shell script is exactly 2?

I have some understanding that to check the number of arguments being passed into the shell script all I have to do inside the shell script is this: Example 1 if [ "$#" -ne 2 ]; then do something; ...
0
votes
1answer
19 views

Stopped process reasons?

I'm running a program using a batch file and it keep giving me this ERROR: STOPPED PROCESS I've noticed that the program stops each time in a place a little after the place he stopped the last ...