Newest 'bash' Questions - Stack Overflow

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.

0
votes
2answers
17 views

“… && … || …” (short-circuiting boolean) not identical to “if …; then …; else …; fi” [duplicate]

I have just had unexpected result from writing the alternative form of if/then/else blocks. > #this is the behaviour I expect: > if [[ 1 -eq 1 ]]; then echo "good"; false; else echo "bad"; ...
0
votes
1answer
8 views

Creating a cron to execute a daily mysql dump

I want to create a cron job to execute the following mysql dump on a daily basis and save a csv file to a designated directory. However, I am trying to execute the command from my command line and it ...
0
votes
0answers
21 views

Infinite loop over text large text file

I'm trying to clean out a large log file. The first couple words in each file is the the date in mm/dd/yyyy hh:mm:ss. If this entry is more than six months past the current date, I want to delete it ...
0
votes
1answer
12 views

BASH Increment MAC Address

I've got a valid mac address in a var called oldMAC I need to increment this and then return a new valid MAC Address. In this example I'm incrementing by 1, but it could be by any value. So far I've ...
1
vote
1answer
24 views

Get bash script to open terminal

In Windows when I double-click a Batch script, it will automatically open a terminal window and show me what's happening. If I were to double-click a bash script in Linux, a terminal window does not ...
0
votes
1answer
15 views

How to combine the content of two files by matching the data

I have two files in this format: File1: ID:1 Data:ABC ID:2 DATA:DEF ID:5 DATA:XYZ File2: ID:1 Data:GHI ID:2 Data:JKL ID:3 Data:MNO ID:4 Data:OBC ID:5 Data:XYZ The expected output is: ID:...
-1
votes
2answers
32 views

How to remove an entire string after multiple occurrences of certain characters?

I want to print the entire string which followed by "$" and remove all the other characters and strings. Tried using sed command: INPUT: FINDER=$FILE/$read\ammy.my echo "$FINDER" | sed -r "s|[^a-...
-3
votes
0answers
18 views

Print pyramid and invert pyramid pattern

I am printing pattern,pattern include invert pyramid and pyramid pattern contain invert pyramid and pyramid I can not print in shell script
0
votes
1answer
27 views

Emulate TAB key press in Bash script to autocomplete

I have simple Bash script running command in Kubernetes, however I need autocomplete in one command to continue: #!/bin/bash DATE=$(date +%Y-%m-%d_%H:%M:%S) printf "Available Kubectl contexts:\n\n" ...
1
vote
1answer
17 views

launch several “while read” commands with xargs

I have a file that contains a list of commands like this while read line;do tabix ftp://.../myfile.gz. >> output.vcf; done < input.txt and I would like to pass this list of 45 commands to ...
0
votes
1answer
20 views

bash: arithmetic expressions inside of variables

I have a simple code to assign variables in loop based on simple ariphmetic equaltion # assign initial value restr_start='25' # assign a new variable, which is a number that will decrease ...
0
votes
1answer
31 views

Bash selection menu based on command output

How can I make a selection menu based on other command output? For example running following command: kubectl config get-contexts I am getting following output: CURRENT NAME CLUSTER ...
0
votes
0answers
14 views

Variable in Path gets cut in half at whitespace

I want to include a Directory name with whitespace into a path variable. Problem: When summoning the variable $curr_op="PDF Komprimieren" the Output shows me that only "PDF" got summoned into the ...
-1
votes
0answers
14 views

Gradle wrapper build failure : The SDK directory does not exist?

I am trying to build an android project in WSL using gradle. But when I execute the command gradle wrapper in the root directory of my project I get the following error: * What went wrong: A problem ...
-5
votes
1answer
57 views

How to do git checkout and git pull on a branch using a BASH or Python

I want to do first a git checkout to a branch and then do git pull on this branch. if the pull request can't be done i want to get an error message. I'm thinking of using BASH or python but i have ...
0
votes
1answer
22 views

Permission denied (publickey) sudo ssh -i <pem file> ubuntu@ip?

I’m connecting a ec-2 instance with my ubuntu terminal, and and I am still facing a problem Permission denied (publickey). When i run following command sudo ssh -i Desktop/iris.pem ubuntu@13.127.228....
-2
votes
1answer
28 views

Listout file created on sunday using shell script

**I have files in my directory. Files name is as below. Backup-2018-07-29.tar.gz Backup-2018-07-30.tar.gz Backup-2018-08-05.tar.gz Backup-2018-08-06.tar.gz Connectly-2018-08-05-05.tar.gz meraBoxDump-...
-1
votes
2answers
32 views

How to change directory to a directory where a job(PID) is running in linux?

I can check where a job is running with pwdx <PID> I want to change directory into that specific directory. As of now, I just copy the directory name and 'cd' into it. What I want is a compact ...
0
votes
0answers
28 views

Script asking for confirmation despite using -y

I am trying to develop a script to setup software and some firewall rules. This is run on a fresh VPS while connected via SSH as the root user. There are 2 points in the script where it appears to ...
-2
votes
1answer
44 views

How to automatically send “yes” to ssh prompt in shell script?

This is the line in my shell script (runs on Azure cli) which asks for "yes/no". How do I automatically give an input? ssh $adminUser@$serverIp'./new_script.sh' $paramOne $paramTwo The server I am ...
1
vote
1answer
19 views

Transferring large files using SFTP using linux bash scripts

I am intending to send a huge file around 1+GB over to the remote side using SFTP. However, it seems to work fine in interactive mode(when I sftp@xx.xx.xx.xx and enter the password manually, then I ...
0
votes
1answer
21 views

How to create cron job to run shell script every minute

I wan to create cron job that runs a shell script every minute I've tried editing contrab -e with: 1 * * * * sh ~/test.sh to no avail
0
votes
0answers
20 views

Exporting associative arrays from one script to another

I have a bash script which basically contains all export variables and I am trying to add associative array into that script. This is my export's script: #!/bin/bash export declare -A oldLinks ...
1
vote
2answers
18 views

Makefile: Syntax error /bin/sh: -c: syntax error: unexpected end of file

I have a simple Makefile: git_repo := some_git_repo repo: if [ -v $(git_repo) ]; then \ echo "exists!" \ else \ echo "not exist!" \ fi; clean: repo Running make clean ...
1
vote
2answers
39 views

How can I capture a result about a SQL query and put into a variable using <<EOF in bash? [duplicate]

I need create a linux script and in this script I need capture the result of the SQL query in Oracle and put into a variable for example: sqlplus -s /nolog<<EOF conn c##myuser/mypassowd col ...
0
votes
1answer
25 views

Should there be duplicate information in my path on my mac?

I used this command multiple times export PATH=“/usr/local/opt/mysql@5.7/bin:$PATH” Now it seems this caused me to have duplicate information in my $PATH. echo $PATH “/usr/local/opt/mysql@5.7/bin:...
0
votes
1answer
37 views

Is there an way to get any button pressed in ubuntu, even those not pressed inside my C/C++ application window?

I'm developing a small app that will show an alert whenever I haven't pressed any key or clicked any mouse button for a while, just for helping me focus. But, I can't find a way to get buttons pressed ...
0
votes
2answers
45 views

Stripping Specific Information with Bash

I have a small bash script that looks at the chassis temps on a Dell server. The script will be running against 50 servers from Icinga2 and report the findings into Granfana via Influxdb. I need to ...
0
votes
0answers
15 views

Use argument as json attribute value [duplicate]

I'm using jq to transform JSON in bash. How do I use the value of a bash variable as a JSON attribute in jq? #!/bin/bash TableName="Test" aws dynamodb scan --table-name ${TableName} --endpoint-url ...
0
votes
1answer
19 views

jq command throws error “cannot iterate over string” when

I am writing a bash script utilizing jq to filter out JSON entries given some bash variables and return some of the key values from each entry into a tab-delimited file. I think the first few lines of ...
0
votes
1answer
12 views

How to escape quotes in bash array elements [duplicate]

I want to create an array like so array=( "element1 with "quoted string"" "element2 without double quoted string" "element3" ) After running the code it outputs echo ${array[0]} ...
0
votes
0answers
20 views

bash shell script to subtract milliseconds from a given timestamp

I have a bash shell script where I take an inputDate string and then add some months to it to get a new date and then I format it as timestamp with milliseconds as below START=2017_01_01; i=1; ...
0
votes
0answers
30 views

cd into a specific directory changes PATH variable

When I change directory (cd) into one specific directory (which contains a rails application) it changes the PATH variable, removing many directories from PATH including /bin, /usr/bin, and /usr/local/...
-1
votes
0answers
39 views

Delete all lines between two strings that include special characters [duplicate]

I tried looking for similar questions but none that I found answered the questions I have (I'm somewhat new to Linux and Bash so I might have some more fundamental questions I'm not realizing). My ...
0
votes
0answers
34 views

How to write a bash script to set up working environment?

I want to write a bash automation script to set up my working environment. Like every day I need to open 7 tabs of the terminal with each service running different command and I also open eclipse and ...
0
votes
0answers
21 views

Bash Script. Enter Username and Password

I'm trying to write a script that calls another one. Then it should fill in username and password. Unfortunately spawn does not call my script file. I created both scripts and then created them with ...
0
votes
3answers
28 views

How to find a similar file to a given file into a directory with returned value of diff command?

I am looking for a way to find (one)/(multiple) files that (is)are identical to a given file. I would like to perform this with bash shell using the commands findand diff I have tried the following ...
0
votes
1answer
42 views

error reading input file: Key has expired

I am currently making a bash script. The purpose of this script is not important. However, I have a piece of code that is generating an error. The error is as follows: ./script.bs: line 175: read: ...
0
votes
1answer
25 views

How to capture wall-clock time and CPU time in a Python variable using bash builtin 'time'?

I am working on a Python script that is going to be run in the command line. The idea is to get a command from the user, run it and then provide the wall-clock time and the CPU time of the command ...
0
votes
2answers
26 views

How to convert individual IPs to ranges based on matching column data in CSV

I need to group csv data in a way such that unsorted consecutive IP addresses that have the same port data (column G) are combined into a range. sort --field-separator=',' -k 7 -k 6 $filename.tmp1 &...
0
votes
1answer
29 views

how to get a string using shell script commands? [duplicate]

I have a file that contains the following data: __NV__: 1 name: "MEP-UI-CUSTOMER-INFO-TXT" desc: "MEP Customer Name Information" fpath: "mep/frontend/ui/primecast/assets/i18n/custom-info.txt" fdata: "...
0
votes
0answers
16 views

How to use lxc exc to issue multiple commands as specific user

My goal is to execute two commands in a specific folder as ubuntu from outside of it's lxc container. I've tried a couple of things but I figured this example is the closest I have to working. If I ...
1
vote
2answers
72 views

How to convert a JSON array to a CSV row?

I'm trying to convert a large JSON file to a CSV format. (I've just learned how to use jq so I'm still a beginner). I've successfully managed to convert most of the data, however, I'm stuck at an ...
0
votes
1answer
14 views

Bash to php regexp

I have a bash script that tails a file for a string that contains either "CONNECT" or "DISCONNECT". Once such a string is found that string is then piped to a php sript. Here is the bash script: ...
0
votes
1answer
37 views

Where´s the Issue with the EOF line?

I´ve changed from SuSE to RHEL and trying to us same code, I´m geting some error related with identation, I believe. SuSE was using bash3 and RHEL it´s using bash4. Error message: -bash: test.sh: ...
-1
votes
0answers
30 views

Running a Bash script results in 'Bad interpreter: No such file or directory error'

I have problem this error: bash: /drives/C/Users/deolit/DOCUME~1/MOBAXT~1/slash/tmp/MOBASC~1.SH: /usr/bin/expect: bad interpreter: No such file or directory My configuration for Shell in MobaXterm:...
0
votes
1answer
16 views

docker-compose.yml passing arg to build from file contents

I would like to read contents of a file specified by an environment variable and pass it to docker-compose as build arg. So then in my Dockerfile I can do: ARG MY_FILE RUN echo "$MY_FILE" > /my-...
2
votes
2answers
47 views

escaping complicated command line arguments in bash and ssh

I am working on a bash script to retrieve uptime of a list of servers. It just reads from a file and executes a remote command on the server. Some servers may have been up for a long time while some ...
0
votes
1answer
21 views

How to unzip a folder passing a variable?

I am trying to unzip a folder by passing it a variable in Google-colab. However when I do it, it doesn't show up in my folders. If I do it by passing it directly the name, like in this answer here: ...
-1
votes
0answers
16 views

Grant user access to a folder and execution rights to its content [on hold]

How to grant a Linux user access to a folder and execution rights to everything inside it? I've got a script I need to run on a remote machine via SSH but I want to limit the rights to a specific ...