Questions tagged [bash]

38840 questions
1

votes
1

answer
66

Views

clear piped output without interrupting program?

I am running a program (pianobar) piped to a text file, that outputs every second. The resulting file ("pianobarout.txt") needs to be cleared regularly, or it grows to massive proportions. However, I do not want to stop pianobar to clear the file. I have tried running > pianobarout.txt as well as...
Greg Schoppe
1

votes
2

answer
1.4k

Views

Downloading all Urls accessible under a given domain with wget without saving the actual pages?

Trying to determine all the valid urls under a given domain without having the mirror the site locally. People generally want to download all the pages but I just want to get a list of the direct urls under a given domain (e.g. www.example.com), which would be something like www.example.com/page1...
fccoelho
1

votes
2

answer
30

Views

Text Processing…print the 1st occurrence of pattern1 and 8th and 9th occurrence of pattern 2

I have a text file and I want to print the 1st line starting with pattern "abcd" and also the 8th and 9th lines which are started with "DDD" pattern. Any sed or awk for doing that?
chimoshoto
1

votes
2

answer
1.5k

Views

How to extract a link from an html file using bash

I am trying to create a shell file that will grab all of the images from the toplist of wallbase.cc. So far I have it so that it curls the html code (using mac so no wget), and grabs all the links to the images. The only problem I am having is that when I grep for the links it returns . What I a...
QuinnFTW
1

votes
3

answer
124

Views

Convert quoted string list to specific format

I'm using jq to read some data from a JSON file. after=`cat somefile.json | jq '.after[]'` returns something like this: "some value" "another value" "something else" Basically a list of quoted strings. I now need to convert these strings into one string formatted like "some value; another value; som...
Collin Henderson
1

votes
1

answer
586

Views

Exiting a function with trap and its error code

Let's assume I have the following function: #!/usr/bin/env bash f(){ trap 'printf "\nAborting\n"; return 1' SIGINT sleep 10 return 0 } If I run f and wait those 10 seconds and then do $ echo $? > 0 That's expected. But if I run f and hit Ctrl+c, the function f is aborted, but $ echo $? > 0 instead o...
pfnuesel
1

votes
2

answer
281

Views

ImageMagick: Possible to remove middle in picture?

Question As an example, is there an easy way to crop away the o's in the Google logo (knowing their coordinates in advance)? The result should then be "Ggle" with a smaller image width than the original because the o's are missing. It doesn't have to be done with ImageMagick. It could also be Gimp,...
Sandra Schlichting
1

votes
1

answer
144

Views

Counting the Number of Characters in a File Using Bash and Assigning to Variable

I need to loop through a text file provided and count the number of characters in the file. The file will only contain one word that I am supposed to analyze. So basically, I just need to know the length of the word. I want to assign the length to a variable that I have defined in the bash file....
Otto45
1

votes
1

answer
203

Views

How to grep a file and output the matching part of a line plus a few surrounding words?

I am searching a file for a pattern and would like to limit the output so that it does not display the whole line, but a match surrounded by a few words, so I can see the context. The lines are too long to comfortably view the whole line in the output. I'm looking for a solution with grep, awk, and/...
dabest1
0

votes
0

answer
7

Views

“bash: sysctl: command not found” in debian:stretch-slim

when I pull the debian:stretch-slim from hub.docker.com, and then run a container(root), I find that bash: sysctl: command not found. How can I use sysctl in debian:stretch-slim? and many images are builded from debian:stretch-slim, so when I want to use sysctl in some other containers like that:...
Wei
2

votes
0

answer
19

Views

API loop that inserts page parameter

I am trying to work with the API documentation for an app. In order to call it, I'm using the code: curl -X GET \ 'https://api.program.com/v1/notes?page=1&pageSize=1000&sort=desc' \ -H 'Authorization: Bearer xxx123xxx456xxx789xxx0001' \ -H 'cache-control: no-cache' The token is changed here for obv...
gooponyagrinch
0

votes
0

answer
4

Views

How to duplicate ssh session to a new window/tab from gnome-terminal without using tmux/screen?

Suppose i logged into a ssh session. and i want to open new window with same ssh session. i know it's possible with tmux or screen. i don't want to use those tools. is there any way to do it. using this will helps up to some extent ssh -M server.com 1.does tweaking bashrc helps here? 2.does creating...
Akhil Jalagam
1

votes
1

answer
228

Views

Bash - error code in if statement not working

I am writing a bash script which does a backup to a mounted drive. The backup itself works fine however even if there is an error during transfer it will say its successful. backup() { echo -e "Backup Started\n" >> $1 echo -e "Mounting backup Drive" >> $1 mount $2 /mnt 2>>$1 if [ $? -eq 0 ] ; then e...
user3600401
1

votes
1

answer
44

Views

How to rearrange a list of lines in all possible ways and write those to files via bash script?

I did some measurements and got a list of 132 lines in a csv file. The data looks like this: 13,5;26;10;45,2;48,3 13,5;26;15;49,7;52,9 13,5;26;20;54,8;58,0 I would like to write all possible combinations of those lines into files, from outputs of a single line to a maximum of 44 lines. The order in...
Markus Hern
1

votes
2

answer
1.6k

Views

Bash Script - Exclamation Point within Variable Reference

I'm looking over a script (which has been used successfully in the past) which contains the following: node=1 while : do userKey=WEB_${node}_USER userVal=`echo ${!userKey}` I have not been able to figure out why an exclamation point would be added to a variable reference like this. What purpose does...
1

votes
4

answer
361

Views

how to kill a single background process in bash

I want to kill a single background process in bash $SCRIPT_DIR/utils/monitor.sh -f $root/save & $SCRIPT_DIR/utils/run.sh -f $save $SCRIPT_DIR/utils/Monkey.sh -f $save I want to kill monitor.sh after finishing Monkey.sh. I tried using pid but its not working.
MakeThingsHappen
1

votes
1

answer
356

Views

BASH local and flock

I try to use a flock like here https://stackoverflow.com/a/169969 but within a function ... and I try to update a local variable (locale to the function) from within the flock part, but it seems not update ... cat test.sh #!/bin/bash function _job_worker() { local z=1 local result= ( # Wait for lock...
Stéphane MERLE
1

votes
1

answer
1.4k

Views

Is there any git bash with nice interface for Windows? [closed]

Recently started git in bash, after understanding the basics of code mode, but found it feeling bogus using git with a command prompt-like interface of Windows. I'm wondering is there any easy way I can change the default interface to something cool! What I can most is to use the "Properties" menu a...
Mayeenul Islam
1

votes
2

answer
114

Views

Bash tokenizing quoted string with spaces as individual words

I'm trying to execute the following commands: mkdir 'my dir' CMD="ls 'my dir'" RESULT=$($CMD) This results in: ls: 'my: No such file or directory ls: dir': No such file or directory Using "set -x" before the second command reveals that the command that's actually being issued is: ++ ls ''\''my' 'dir...
cameronhimself
1

votes
3

answer
880

Views

Modifying $PATH variable by a bash alias

I created this alias in my .bashrc file: alias changepath="export PATH=$JAVA_HOME/bin:$PATH" What I want to do is change $JAVA_HOME and then change the $PATH to include the new $JAVA_HOME/bin. When I change $JAVA_HOME and type this command instead of using the alias, it works as expected. However, w...
salmonalive
0

votes
2

answer
11

Views

Is there a way to prepend to a bash array without writing a function?

Start with arrayA values below. arrayA=(‘valueA’ ‘valueB’ ‘valueC’) *…Clever_One_line_Statement_goes_here…* After …Clever_One_line_Statement the arrayA has the values.... arrayA=(‘’ ‘valueA’ ‘valueB’ ‘valueC’)
paulhr
0

votes
1

answer
17

Views

How would I create a script file to read and generate a username from a txt file?

I have a file called "list.txt" and I need to create a script file to generate the username and initial password for a list of students from the file. This is an example of what the lines from the .txt file look like: [email protected] Soc.Sec.No. *--------Name-----------* Class *School.Curriculum.Major.* Ca...
Audrey
-1

votes
1

answer
22

Views

Not able to sort by date in python

I have a bsh script that has a while loop which a python script to check SSL cert expiry date on a bunch of hosts. The script executes perfectly and outputs: domainA--> expiry_date_A domainB--> expiry_date_B I need to be able to sort by date so I can know which expire soon. Here are the scripts: **c...
Bes
1

votes
4

answer
1.7k

Views

Bash Shell Scripting - Select Case Menu Not Working

i'm quite new to shell programming.. and working on project am doing Select Menu using the Select Case below is the scripting #! /usr/bin/bash echo "1) Add new book" echo "2) Remove existing book info" echo "3) Update book info and quantity" echo "4) Search for book by title/author" echo "5) Process...
Preeyah
1

votes
3

answer
103

Views

Easy replace with/without regex in multiple files

Hundred times a day I need to search for patterns in files and sometime I have to replace these patterns with something else. Most of the time it is simple patterns like a word or a short sentence but sometime I have to look for more complex regexp. I don't really like sed (at least the sed version...
nowox
1

votes
2

answer
7.2k

Views

Unix Bash - Assign if/else to Variable

I have been creating to assign the output of if/else to a variable but keep on getting an error. For Example: mathstester=$(If [ 2 = 2 ] Then echo equal Else echo "not equal" fi) So whenever I add $mathstester in a script, laid out like this: echo "Equation: $mathstester" It should display: Equatio...
space149
1

votes
3

answer
331

Views

concatenate the result of echo and a command output

I have the following code: names=$(ls *$1*.txt) head -q -n 1 $names | cut -d "_" -f 2 where the first line finds and stores all names matching the command line input into a variable called names, and the second grabs the first line in each file (element of the variable names) and outputs the second...
brucezepplin
1

votes
3

answer
1.1k

Views

sed to replace multiple lines and output to same file

I have a text file like below name: xyz ip: x.x.x.x network: abc gateway: def name: xyz ip: x.x.x.x network: abc gateway: def The above 2 blocks of code, I want to write a multi-line sed command which can replace 'name' and 'network' information and then redirect it to the same file I tried below wh...
skyrocker
1

votes
2

answer
1.7k

Views

Difference between git “open existing repository” and “clone existing repository”

After installing Git Bash, right clicking a new blank folder in Windows Explorer and hit Git Gui I get the form as snapshot. As a SVN user, I can't tell the differences between open and clone action from the UI. What are the differences between the two i.e. in SVN I just have check out command? A qu...
Nam G VU
1

votes
3

answer
132

Views

How to print two variables line by line

I am looking for a way to print line by line on shell. For example, I have the following variables A and B that contains: | A | B | | a | d | | b | c | | c | b | | d | a | What I want as the output is: a d b c c b d a I have tried awk 'BEGIN {OFS=" "}{ getline line < "$A" print $0,line } ' "$B"...
Minato Arisato
1

votes
1

answer
95

Views

How can I check for the current path in bash?

I'm working on multiple projects : A, B, C, D, E and F. I go though all my projects via Terminal, and swapping between them via Terminal Tabs. Sometimes, I confuse between projects because they have the same text color, in this case is yellow. I'm trying to achieve something like this: I would l...
kyo
1

votes
2

answer
570

Views

expect fails when running proc inside proc

My script works fine (retrieves sftp prompt) when using one proc. But when I try to use proc inside proc, script gets stuck, and I do not know why. Please do not refactor the code, that is not the point, I need to understand what is the issue here. Working code: proc sftp_connect {} { set times 0; s...
meso_2600
1

votes
1

answer
2.7k

Views

How to get the file creation date/time in xfs

I am able to get the file creation date/time using debugfs command in ext file system but how to check/get the same in XFS file system.
1

votes
2

answer
33

Views

remove rows/lines from a file that do not meet a criteria

How do I remove rows that do not meet a certain criteria from this. $ head -n 50 countries_lat_long_int_code2.csv | tail -n 25 BJ,9.30769,2.315834,Benin,229 BM,32.321384,-64.75737,Bermuda,1 BN,4.535277,114.727669,Brunei BO,-16.290154,-63.588653,Bolivia,591 BR,-14.235004,-51.92528,Brazil,55 BS,25.034...
HattrickNZ
1

votes
2

answer
121

Views

grep, ignoring the last line of the file if it does not have a newline

When greping through files that are still being created by other processes, the final line is often incomplete and doesn't yet have a newline at the end. Is it possible with grep (or some alternative like sed), to ignore this line? I don't want to just automatically always ignore the last line, beca...
Aaron McDaid
1

votes
2

answer
1.4k

Views

run script form .bashrc only once

I want a python script to be executed at bootup on my raspberry pi2, so I put it into .bashrc. Launching the script with crontab didn't work. But I only want to execute it once. Not everytime I enter a terminal or every time I login via ssh. My poor try of course didn't work and it's obvious why. py...
Sadik
1

votes
2

answer
1.6k

Views

How to get absolute path of a directory?

I want to automate the following thing: cd into current directory cd workdir make a new directory mkdir mydata and get the absolute path to this mydata directory
Hello lad
0

votes
0

answer
19

Views

Output in Variable

I am writing a new script for a backup solution. Now I want to get the error message, which I saw in terminal, to a log file. Therefor I want to write the output in a variable. I wrote an error in it. The option "defaults-file" is missing a "--". With a simple example it worked: #!/bin/bash log=...
muelleste
1

votes
3

answer
4.7k

Views

Extract data from JSON file using bash [duplicate]

This question already has an answer here: Read the json data in shell script [duplicate] 4 answers Let's say that we have this kind of JSON file: { ... "quotes":{ "SOMETHING":10, ... "SOMETHING_ELSE":120.4, ... } } How can I obtain those values and use them in order to add them together? Am I ab...
Thodoris
1

votes
1

answer
3.4k

Views

How to pass a header as argument in curl command? [duplicate]

This question already has an answer here: Why does shell ignore quotes in arguments passed to it through variables? [duplicate] 3 answers I am attempting to do a curl command that uses a predefined variable as a header. header='-H "Content-Type: application/json" -H "userGUID: 7feb6e62-35da-4def-88...
Alex S

View additional questions