Questions tagged [bash]

51381 questions
0

votes
0

answer
6

Views

How can I use a variable in if condition in expect script?

I am executing expect script on a remote host(say A) and I want to fetch some environment variables from that remote host(A). Depending on the remote host's(A) environment variables, I would like to perform some conditional operations on that host(A) and on the host(B) from which the expect script i...
Ravi Kiran
1

votes
2

answer
6.2k

Views

Aws Ec2 run script program at startup

There is a method to setup an EC2 machine to execute Kafka starting script on startup? I use also java Aws SDK, so I accept both solution for a program java that run command on EC2 instance and solutions for a bash script mode that run kafka script at startup.
2

votes
1

answer
18

Views

Weird behavior of calling docker run from bash script

I try to run docker run from bash script and docker says: “is not a docker command” If I print the docker command line before I called docker and I copy it to clipboard and paste it to command line it works well! here is the command in bash script: local args='run ${nw_param} ${opts} --name ${im...
zamek z
1

votes
1

answer
198

Views

Why is this Bash script not inheriting all environment variables?

I'm trying something very straightforward: PEOPLE=( 'nick' 'bob' ) export PEOPLE='$(IFS=, ; echo '${PEOPLE[*]}')' echo '$PEOPLE' # prints 'nick,bob' ./process-people.sh For some reason, process-people.sh isn't seeing $PEOPLE. As in, if I echo '$PEOPLE' from inside process-people.sh, it prints an em...
Nick Chammas
1

votes
3

answer
316

Views

How to print first word of first line and last word of last line in unix in a file

Suppose there is a file file1.c It has 100 lines . I need to print first word and last word of that file.
user265906
1

votes
1

answer
243

Views

-bash: ./deploy.sh: Permission denied , ERROR: script returned exit code 126

I am trying to implement continuous deployment using Jenkins and that involves sending a jar file to a remote server and start the jar once its on the remote server. The problem is that i keep getting access denied error and i have tried every account i have on my remote and local server nothing se...
Erent
1

votes
1

answer
1k

Views

SFTP bash shell script to copy the file from source to destination

I have created one script to copy the local files to the remote folder, the script is working fine outside of if condition but when I enclosed inside the if condition the put command is not working and logged into the remote server using sftp protocol and when exist it's showing the error: put comm...
Ashish Sood
1

votes
1

answer
98

Views

how to read chunks from named pipe in bash

i have a command that potentially outputs a lot of data to stdout and I need to upload that via ftp to a remote location. I found this question Upload output of a program directly to a remote file by ftp and I really liked the idea of redirecting the output into a named pipe and then read junks from...
user3347114
1

votes
2

answer
47

Views

How can I get the name of the last person who committed on a remote?

I know that the option -force-with-lease allows me to push force only if I was last committer but I would like to allow overriding it: git push playground $current_branch:master --force-with-lease if ! [[ '$?' == '0' ]]; then last_committer='$(git some command)' ask_continue 'the last committer was...
Ulysse BN
0

votes
2

answer
14

Views

Correct Regex in SFTP bash script

I want to automate a SFTP process to transfer the last file created in local server and send it to remote server. In local server I have '/Source/Path/' I have files named like below: Logfile_2019-04-24 Logfile_2019-04-24_old.txt This is my current script: dyear=`date +'%Y' -d '1 day ago'` dmonth=`d...
Ger Cas
0

votes
0

answer
10

Views

bash - file name in the content

would you be able to help me a bit. I try to write a short script which will find in the current directory all files that contain their name in their content. I was trying with the below but still can't find good solution to the problem: #!/bin/bash for i in *; do if [ -f '$i' ]; then z=`cat $i | gr...
axel_87
2

votes
3

answer
76

Views

Set file modification time from the date string present in the filename

I'm restoring a number of archives with dates within their names, something along the lines of: user-2018.12.20.tar.xz user-2019.01.10.tar.xz user-2019.02.25.tar.xz user-2019.04.19.tar.xz ... I want to set each file's modification date to match the date in their filename by piping the filenames to t...
tobiasfried
1

votes
3

answer
114

Views

How to iterate a JSON array in bash from jq

Background I want to be able to pass a json file to WP CLI, to iteratively create posts. So I thought I could create a JSON file: [ { 'post_type': 'post', 'post_title': 'Test', 'post_content': '[leaflet-map][leaflet-marker]', 'post_status': 'publish' }, { 'post_type': 'post', 'post_title': 'Number 2...
bozdoz
1

votes
1

answer
28

Views

Why does eval “$BASH_COMMAND” crash bash?

If you run eval '$BASH_COMMAND' in the terminal, it will crash and the terminal window will disappear. I have not been able to understand why this particular command crashes bash. The strange thing is that when I run echo '$BASH_COMMAND', this happens: $ echo '$BASH_COMMAND' echo '$BASH_COMMAND' Ano...
1

votes
2

answer
70

Views

Bash - More efficient way to process csv file than grep [closed]

Updated I have a file (file.txt) with a list of words: apple banana cherry orange pineapples I have a csv file (data.csv) that contains lots of data: 1,'tasty apples',3,5 23,'iphone app',5,12 1,'sour grapes',3,5 23,'banana apple smoothie',5,12 1,'cherries and orange shortage',3,5 23,'apple iphone or...
Lou Diamonds
1

votes
5

answer
88

Views

Match strings from two files and output fields in specific order

I have the following two files. query.txt pumpkin kiwi subject.tsv kiwifruit something green melon something red pumpkinhead something orange I'd like to loop through query.txt and check for each line if any first field in subject.tsv contains the line. If yes, a tab plus the third field f...
Matthias
1

votes
2

answer
51

Views

How to output first line of curl result in a file with bash script

I want to read a file of urls, curl each url and only get the first line which contains the HTTP code. I am running under Windows 10 inside Cmder. #!/bin/bash input='urls.csv' truncate -s 0 dest.csv while IFS= read -r var do result= `curl -I ${var%$'\r'} | grep HTTP $result` echo '$var $result' >> d...
Yvon Huynh
1

votes
2

answer
35

Views

Parent trap visible but not run by subshell

Tested for Bash 5.0.2 According to the GNU Bash Reference Manual, Bash performs the expansion [of a command substitution] by executing [the] command in a subshell environment According to The Open Group Base Specifications Issue 6: when a subshell is entered, traps that are not being ignored are se...
Marcus Rossel
1

votes
1

answer
25

Views

Bash grep output in addition to echo within if statement

I have a simple script that checks if images are being used within our html directory. I have a file called imageserver.txt which looks like: imageserver/icons/socialmedia/sqcolor_tumblr.png imageserver/icons/socialmedia/sqcolor_gaf.png imageserver/icons/socialmedia/sqcolor_yelp.png imageserver/ico...
Zak
1

votes
2

answer
30

Views

Sort numeric values except text in Bash

I have a csv file called prices.csv that looks like this: Name, Price, Description Apple, 2.85, fruit Kiwi, 1.96, fruit Banana, 0.99, fruit Peach, Not available, fruit Orange, 2.02, fruit I would like to sort the second column (Price) in ascending order, except for the values that are 'Not available...
vincers
1

votes
1

answer
43

Views

npm script is ignoring arguments of grep command

I have handy command for looking for TODO notes in my files. It works fine directly from the command line (ubuntu). This is the plain CLI command: grep -lir --color --exclude-dir={node_modules,libs} --exclude=package.json 'todo' And this its occurrence in package.json { 'private': true, … 'scripts...
bitstarr
1

votes
2

answer
42

Views

Start two never ending python scripts

Is there a proper way to start two python scripts that will never end? I have a Bash Script.. I just want it to start two python server applications on different ports. But obviously as I get to the first python command, it will loop forever is there a way to kill these two python scripts when you k...
billybob2
1

votes
2

answer
55

Views

parse file and date manipulation in bash with a large file

I'm looking for a better way to manipulate a date format into something that I want. I do manage to do it, but I have to process the files several times because I can not get date to do it in one pass. The format I have: Wed Jan 30 08:00:00 2019 : misc data The format I want: 30/01/2019 08:00:00 : m...
Madivad
1

votes
3

answer
52

Views

Why is “ls -1 $fl | wc -l” not returning value 0 in my for loop?

I am trying to add a condition in a for loop to check the existence of a file as well as check for file size > 0 KB. Period file contains monthly data: 20180101 20180201 20180301 20180401 20180501 There are individual files created for each month. Suppose a file is not created for one month, (201802...
user8611207
1

votes
1

answer
36

Views

Why does “a=( * )” assign an array with one element for each filename in '*' instead of each word?

Question Details Suppose we have a directory with three files in it: file_1, file_2, and the very inconveniently named file 3. If my understanding of filename expansion is correct, the way bash interprets the string echo * is that it sees the (unquoted) *, and modifies the string so that it now read...
jgaeb
1

votes
2

answer
54

Views

Fetch the values from a string with regular expression in bash

I have a string and I want to extract the needed values from this string, so I wrote some regex patterns, I searched in google and I find I have to use echo command and then store in a variable. I tested my regex pattern with regex101.com and the pattern is correct but I don't know why not work in b...
MajAfy
1

votes
2

answer
50

Views

Merge File1 with File2 (keep appending from File1 to File2 until no more rows)

I can't find a solution. So here is the problem. Result should be 100 rows (File1) with contents from File2 repeating 25 times. What I want is to join the contents even though the number of rows is not equal. Keep repeating including lines from File2 until number of rows from File1 is met. File1: te...
Jax
1

votes
3

answer
57

Views

grep for a variable that contains “+”

Trying to pickup the second row using grep and it dosent work if it has a '+' character i have tried with fgrep & instead of -P tried with Fx or x and -w but none of them worked. File prereq.txt contains this : WS+1 whatever 2222 WS--1...
Yashas K.M
1

votes
1

answer
49

Views

How to empty an array in bash script

I am trying to get specific information from a bunch of files. Iterating over a list of files,greping for what I need. I know for sure that each grep will give more than 1 result and I want to store that result in an array. After finishing the work specific to file, I want to erase everything from a...
gkr2d2
1

votes
2

answer
30

Views

How can i capture request headers using Bash

I need to make a script that can get a access token located in the request headers of a website can anyone help me with it?
Ashu Zucced
1

votes
3

answer
50

Views

How do I flatten JSON data of the Pandascore E-Sports GET response format to have a very clean dataframe in pandas?

I am trying to get a nice pandas dataframe of a JSON file I got from the PandaScore REST API. I realize that in order to do this, I need to flatten the values which contain lists and dictionaries, but I am getting errors. For this reason, I was not sure exactly how to proceed. As far as the datafram...
pythonRCNewbie
1

votes
2

answer
69

Views

Get Windows username from Bash Unix shell?

Is there a way to get the Windows' username of the user who's connecting to a specific Unix environment, using always the same server's credentials, directly in Bash? Some background There is a population of N users, who may connect to M different Unix environments always using the same credentials...
Matteo NNZ
1

votes
2

answer
29

Views

sed using dollar sign for both environment variable and end-of-line pattern matching [duplicate]

This question already has an answer here: Using dollar sign in sed for both variable replacement and character 3 answers In sed, we use double quotes to read environment variable indicated by a dollar sign, what should i do if I want to use the dollar sign for end-of-line pattern at the same time?...
once
1

votes
1

answer
44

Views

Why does storing my regex in a variable break the comparison test? (Awk/Gawk)

I have a file called regeces containing a number of line-by-line regexes. Here's an example: The .* is .* years old I like .* with lots of .* I also have a data file very creatively called data: The car is 3 years old I like pizza with lots of pepperoni I like tacos with lots of cheese The house is...
Andrew
1

votes
3

answer
52

Views

need to clean file via SED or GREP

I have these files NotRequired.txt (having lines which need to be remove) Need2CleanSED.txt (big file , need to clean) Need2CleanGRP.txt (big file , need to clean) content: more NotRequired.txt [abc-xyz_pqr-pe2_123] [lon-abc-tkt_1202] [wat-7600-1_414] [indo-pak_isu-5_761] I am reading above fil...
Junipar70
1

votes
3

answer
27

Views

I can't use bash 5 syntax even after configuring it in MacOSX

I am relatively new to bash. I had bash 3 In my mac by default. GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18) Copyright (C) 2007 Free Software Foundation, Inc. I believe that I've installed and configured bash 5 for MacOSX. Running bash -version command outputs: GNU bash, version 5.0....
hamza belmellouki
1

votes
1

answer
20

Views

convert first column in a csv file from timestamp to year-month format

Trying to convert first column in a csv file from unix timestamp to date(year-month format) Tried date -d @number'+%Y-%m' and awk, but awk doesn't recognize @ when used together Extract from a csv file : 1556113878,60662402644292 1554090396,59547403093308 Expected O/p 2019-04,60662402644292 2019-03,...
Bt_code
1

votes
2

answer
20

Views

MySQL table outline not appearing when called from shell_exec in PHP

I'm trying to output a visual table of a MySQL result when I run a PHP program similar to the output if I had run the MySQL query straight from the command line. However, when I run the query through shell_exec it does not output the nice table lines around the data. mysql DB_NAME -e 'SELECT * FROM...
cmr
1

votes
6

answer
10.1k

Views

Validate Emails with Bash

I try to validate an email with a shell script. Is there a easy example to validate a mail? Asked google but just found crap and PHP (also crap..). Thanks and regards.
fwaechter
2

votes
2

answer
16

Views

Using brace expansion to move files on the command line

I have a question concerning why this doesn't work. Probably, it's a simple answer, but I just can't seem to figure it out. I want to move a couple of files I have. They all have the same filename (let's say file1) but they are all in different directories (lets say /tmp/dir1,dir2 and dir3). If I we...
Xyz

View additional questions