Questions tagged [bash]

For questions about scripts written for the Bash command shell. For shell scripts with errors, please check them with the shellcheck program (or in the web shellcheck server at https://shellcheck.net) before posting here. Questions about interactive use of Bash are more likely to be on-topic on Super User than on Stack Overflow.

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

Editing GIST with cURL

#!/bin/bash COMMIT=$(git log -1 --pretty=format:'{"subject": "%s", "name": "xxx", "date": "%cD"}') curl -X PATCH -d'{"files": {"latest-commit": {"content": "$COMMIT"}}}' -u user:xxxx https://api....
1
vote
0answers
17 views

Timing execution time for multiple functions in a bash script

The whole code is too long to post here, and the whole thing isn't really relevant. I will do my best at explaining this though and using snippets of code/code examples where I can. I have a script ...
0
votes
1answer
15 views

Java subprocess dying when JVM shuts down

I have a bash file called update.sh which essentially 1. pulls the latest code from github 2. compiles the new code 3. stops the running java server 4. starts the java server again using the updated ...
-1
votes
1answer
21 views

How to read elements of a column one after another to check if they match a certain condition?

-1.4221738 -1.4874885 -1.4994459 -1.5108121 -1.5219439 -1.5332919 -1.5452454 -1.5580290 4.7115221 4.6972045 4.6825012 4.6677902 Let's say, I have a data file like the one before. How can I read the ...
0
votes
0answers
19 views

Linux Error: -bash syntax error near unexpected token 'KERN_INFO"

I just started my CSC 2260 class last week, we are using Virtual Box to work with Linux, and for this assignment we are learning about kernels. I got the hand of adding them, loading them, and ...
0
votes
1answer
17 views

Creating a TCP Server to host ELF files

I've setup a TCP server with docker for a CTF competition I'm going to be hosting. The problem is, when I nc (netcat) into the running TCP Server on my localhost machine, the client does not receive ...
0
votes
1answer
19 views

How do you pipe some values to a node evaluated script?

I can escape the cli arguments node consumers with -- and have hi be my arg that's used in the text node evaluates, but I can't do the same piping a value. j at MBP in ~ $ node -e 'console.log(">",...
0
votes
0answers
32 views

Looping through an array of directories in bash [duplicate]

I am trying to loop through an array of directories using a bash script so I can list directories with their timestamp, ownership etc using "ls -arlt". I am reviewing bash so would like some feedback....
0
votes
1answer
24 views

Bash doesn't display the result of nested if-else statements

I'm trying to nest a couple of if/else statements. Maybe I'm making a very silly mistake but I can't get it to work. There are 3 variables in order, one of them at random will be "-1". If one of them ...
0
votes
0answers
17 views

Open ssh connection on a script, run SSH commands without closing the connection [duplicate]

I'm running a perl script on a linux machine and i need to run it on other node servers in a network which I connect through SSH. Right now I'm just running simple bash commands in the code (i.e. ssh $...
0
votes
1answer
18 views

How to parse text data from end of binary

I have binary file, to which I append some text metadata. It works fine and doesn't affect file in any way. However now I would like to get the data out of the file. The metadata always start with ...
0
votes
2answers
18 views

How to delete files matching specific character placement?

I'm trying to delete files with names that contain certain digits in specific placement. Using bash and text file that contains those specific digits. I have a single directory with files in the ...
0
votes
3answers
24 views

Regex to filter only the first occurance of specific strings

I have the following output from a command substituted variable: 'Enable succeeded: [stdout]Proc is not up yet, retrying...Proc is not up yet, retrying...Proc is not up yet, retrying...Proc is not up ...
-1
votes
1answer
22 views

Bash syntax error: unexpected end of file on fi [on hold]

This is probably a simple one, but i've just started learning bash and i cant figure out the problem, the exact error is "line 37: syntax error: unexpected end of file" wich is the "fi" exit Dont ...
0
votes
2answers
18 views

Sed-Replace immediate next string word coming after a particular pattern but only the first occurrence in a file

I need a sed command which will replace the string immediately after the pattern but only for the first occurrence in a file For replacing first occurrence this was given: sed -i '' -e '0,/abc/s//...
0
votes
0answers
22 views

change filename obtained from request_uri

Can someone help me with the code below: location / { content_by_lua_block { ngx.req.read_body() local filename = string.gsub(ngx.var.request_uri, "/", "") ngx.say(filename) ...
0
votes
3answers
27 views

sed preserve wildcard value inside pattern

I have some app config file tmp.cfg. And need to change some given values inside. Here are the string examples: app-stat!error!25871a5f-9f50-40ac-923d-c80a660fe21d!1!2 app-stat!queued!25871a5f-9f50-...
0
votes
1answer
29 views

Need to remove the last ',' genrerated by my script [on hold]

I developed a code to auto generate ctl file for sqlldr. I ran into one issue, when I generated , next to the column names fetched. The last , need to be removed. I have tried few sed and awk ...
0
votes
1answer
33 views

Write 8bit integers to a file

I need to write 8bit integers to a file. But in bash the default primitive type is string, so if I do it like this: for i in $(seq 1 9); do printf $i | dd of=/tmp/f count=1 seek=$i bs=1 conv=...
0
votes
1answer
27 views

Read a file to variable then replace control charactors with escape charecters

I have a file like below # cat test Start tab enter or with control characters # cat -A test Start^Itab$ enter$ I want to convert file to a variable exactly like below file = "Start\ttab\...
0
votes
0answers
13 views

how to set the output of several commands to a variable [duplicate]

I am trying to get a script on an alpine system to run a .sh file that contains this line. I need the variable LASTNUM to be the output of the other commands when all done with this command in the ...
0
votes
1answer
28 views

Horizontal and Vertical Line Spacing with a unknown variable length

I am trying to print a output with specific format, where output is in a enclosed box. I am using "|" and "-" for creating it. The output I print in between the "|" are variables with Different ...
0
votes
0answers
20 views

Using IFS with echo [duplicate]

Why does this: arr=(1 2 4 8 16) IFS=, echo "${arr[*]}" print out 1,2,4,8,16 (which is what I want) but this doesn't: arr=(1 2 4 8 16) IFS=, echo "${arr[*]}" ? I'd like to have a temporary IFS ...
-1
votes
1answer
21 views

How do I modify this cron script to give date 2 days back

In the crontab, after a script I see a parameter: date -d "($(date +\%Y\%m)-15) day ago" '+\%Y\%m\%d' This generates a date - "20190822" if ran on 23-Aug-2019 i.e. a day back. My questions is: 1) ...
0
votes
2answers
26 views

How to take actual files (without naming it precisely in the script) in the current directory and to process them?

I'm trying to create a script to reduce volume and then merge 5 audio files into one. To process it, I'm using the sox command line. The problem is, I have to rename all the files in the current ...
0
votes
1answer
21 views

Pre-commit hook not ignoring excluded files

My pre-commit script is not ignoring the files specified in my Rubocop yml file, I assume it is because excludes get ignored if I pass files names directly. However, I am not sure how to resolve this ...
-2
votes
0answers
18 views

Issues with passwordless SSH. Doesn't work unless specifying the identify file [on hold]

I'm trying to set up passwordless SSH between two systems. I've done this plenty of times on different systems and can't figure out why it won't work. I copied the public key in to authorized_keys in ....
0
votes
5answers
60 views

Python script runs on command line but not from .sh file

I'm attempting to create a .sh file to batch a number of runs of a neural network on Python whilst on holidays. At the moment I have been calling this from the command line: python ...
1
vote
3answers
53 views

Indexing values from file

I'm desperately trying to achieve a task from work and i just can not figure it out. Short brief: I must monitor a file, witch produce some values. I manage to isolate the values into a separate file ...
0
votes
2answers
25 views

Reading everything but first and last line into a string in bash

I'm trying to read a .csr file into a string, but I don't want the first and last line of the file. I've tried reading the file into a string and then splitting it into an array, but I can't get ...
0
votes
2answers
40 views

How to pass argument in the custom bash function as part of a dir path?

I want to define a custom bash function, which gets an argument as a part of a dir path. I'm new to bash scripts. The codes provided online are somehow confusing for me or don't work properly. For ...
1
vote
2answers
30 views

Find and count compressed files by extension

I have a bash script that counts compressed files by file extension and prints the count. #!/bin/bash FIND_COMPRESSED=$(find . -type f | sed -e 's/.*\.//' | sort | uniq -c | sort -rn | grep -Ei '(...
0
votes
1answer
23 views

Get occurrence of string, containing single or double citation marks using grep

I'm checking usage of translation strings in language.ini. Developers in the project use '', but might use even "" because PHP allows both (even though there's quite a difference between those). Also ...
-1
votes
3answers
33 views

sorting data in a row to multiple rows and columns

I have a data file with the XYZ coordinates of multiple atoms in a molecule. It is in a row separated by "," and every 03 values in the sequence indicate XYZ coordinate of one atom. next three is for ...
0
votes
0answers
24 views

Asking for input into a command for a bash script

I'm trying to use bash to execute a terminal command and pass predefined input as arguments into said command. #!/bin/bash STR="openssl req -new -newkey rsa:2048 -nodes -keyout server.key -out ...
1
vote
1answer
32 views

powershell output in shell

I am trying to collect an powershell script output in a shell script. ssh [email protected] "powershell Test-Path -Path C:/myfile" will if execute in bash just print True . If I save it to variable like ...
0
votes
2answers
35 views

A better way to organize user names, passwords, and other options in bash

I have a bash script that uses ansible to create multiple users on an AWS EC2. One thing that I feel bad about the script is this structure in config.sh: username=( user1 user2 user3 ) passwd=(...
0
votes
0answers
19 views

Unterstanding the dollar in shell with pwd and awk [duplicate]

I am new to Shell command, can anyone help me about these two lines of Shell command. filepath=$(cd "$(dirname "$0")"; pwd) file_1=$(echo -e "${filepath}"|awk -F "$0" '{print $1}') I have tried in ...
1
vote
2answers
30 views

can't change python path and configure for anaconda

I would like to create conda virutal environments and unable to do so probably due to the python path. I have tried to edit the .bash_profile and set the PATH for python but changes are not getting ...
0
votes
1answer
17 views

Assign awk output to variable [duplicate]

I'm trying to assign the output of awk to variable. I tried with solutions specified here but nothing seems to work. I'm first doing curl and then parsing the result from there #!/bin/sh KEY="...
0
votes
0answers
40 views

Am I able to deactivate verbose output in the bash?

I have aliases for many commands with their verbose flags, e.g.: alias ninja='ninja --verbose -j 0' Is there a mechanism in bash, where I can deactivate this flag afterwards? I tried stuff like: ...
0
votes
1answer
43 views

How come my regex isn't working as expected in Bash? Greedy instead of Lazy

How come my regex pattern isn't lazy? It should be capturing the first number, not the second. Here is a working bash script.. #!/bin/bash text='here is some example text I want to match word1 and ...
-1
votes
0answers
25 views

How to match one of two words with regex in bash (non capturing group not working) [duplicate]

I want to match the words "word1" or "word2" as part of a larger pattern. I have it working in a regex tester but it doesn't work in bash because it isn't recognizing the non capture grouping. I'm ...
0
votes
0answers
23 views

What does ${VAR_NAME+x} means in bash/shell? [duplicate]

I have an expression -z ${VAR_NAME+x} which I know will check if ${VAR_NAME+x} is an empty string. But I can't find out what is the purpose of having the +x.
0
votes
1answer
53 views

Creating a file with specific content and at specific path

I have a list of directory locations(Mylist) where I have to create a specific file (Myfile) with customized content for each location. I am trying to use following routine cat Mylist | while read ...
0
votes
1answer
23 views

How to use a BASH variable as a variable on a Javascript file function

I have test.js file and a test.command file. test.js: module.exports.init = function (a) { console.log(a); }; test.command FOO="$(node -e 'require("/test.js").init("Hello")')" ...
0
votes
1answer
15 views

Keep ssh session alive after connecting to mysql

I want to ssh into a remote box, and call mysql inside and start a connection. I can retrieve the password and login to mysql so I wanted to make a script to do this in one go: passwd=$(get_password) ...
0
votes
0answers
25 views

Cannot locate file when running docker container: /usr/local/bin/docker-entrypoint.sh: line 11: exec: “mypackage.sh”: not found

I am trying to deploy a docker container on an AWS lambda. I have followed several different guides (most recently this: https://blog.quiltdata.com/an-easier-way-to-build-lambda-deployment-packages-...
-3
votes
0answers
42 views

.sh script not running? no errors [on hold]

I'm supposed to write a script that validates syntax of given MIPS instructions and splits the contents of an input file into 2 output files (Correct.txt, Incorrect.txt). My code has no errors but ...
2
votes
1answer
36 views

openBinaryFile: does not exist when executing pandoc in Gitlab CI bash script

I am getting this error: pandoc: sh: openBinaryFile: does not exist (No such file or directory) when trying to build some assets with Pandoc in a Gitlab CI bash script. I have a repo, Finnito/...