Questions about bash only, as opposed to other Bourne/POSIX shells. For all Bourne/POSIX-style shells, use the /shell tag instead.

learn more… | top users | synonyms

4
votes
0answers
44 views

KVM reports strange CPU usage peaks (bash infinite recursion)

On a KVM machine running Fedora 20 I ran ulimit -s unlimited (this removes limit on stack size) and an experimental torturing testing script. All this script does is just infinite recursion: ...
7
votes
3answers
447 views

Run a diff between local and remote file

I'm connected on a host via ssh and I'd like to compare (let's say with diff) a certain config file against its counterpart on another host, also accessible via ssh, without having to manually ...
3
votes
2answers
48 views

Getting the current path in .desktop EXEC command

Im trying to make a .desktop file run a .sh which is stored in the same directory as the .desktop. The whole directory needs to be portable and moved from machine to machine. my run script is run.sh ...
2
votes
1answer
37 views

How can I find where LANG, LANGUAGE and MAIL environmental variables are set?

I've had a few issues with environmental variables not set correctly in my Raspbmc Raspberry Pi. Specifically, I've had to manually specify the following in ~/.bashrc. export LANG='en_AU.UTF-8" ...
2
votes
4answers
68 views

Why am I getting inconsistent IP values from icanhazip.com or curlmyip.com?

I wrote a bash script and appended to my crontab to query my IP address every minute, and if it is not the same with the previous query it sends me an e-mail to inform me for the IP address change. ...
4
votes
5answers
293 views

Bash pattern to match all files but directories

In bash, how do I specify a pattern that matches everything but subdirectories in current directory. Given that the pattern */ matches all the subdirectories, I tried (with extglob turned on): $ echo ...
2
votes
2answers
106 views

How to force watch to run under bash

The problem is that when watch is executed it runs sh and I get this error: sh: 1: func1: not found here is the code: #!/bin/bash func1(){ echo $1 } export -f func1 watch func1
1
vote
1answer
23 views

How can I make mailx inform me of new mail?

I'm trying to set up mailx on my server. On one server (Raspbian) I am informed of new mail with a message You have new mail (or something similar). On another machine (Raspbmc), I never have this ...
0
votes
1answer
28 views

Unix - Addressing filename with space for script [duplicate]

I have files Deep.flac and A1 - Rolling In The Deep.flac I wrote the script below, however it can only work with Deep.flac It cannot seem to work with filenames with spaces. I am newbie, learning ...
4
votes
1answer
49 views

Communicating from bash with grunt shell

I'm tired of the slow startup time of hadoop fs just to query HDFS. This isn't a problem with HDFS itself though, because using HDFS file system commands within the Pig "grunt shell" is pretty fast. ...
0
votes
2answers
98 views

If UID=1000 continues, else exit

I am wondering how to implement the following in a bash script. if UID=1000, continue else exit confirm choice (y/n)
3
votes
2answers
25 views

xargs how to put result {} into $(cmd {})? [closed]

for example: find /usr/lib -maxdepth 1 -type l -iname "*libblas*"|xargs -I{} echo "{} =>" $(realpath {}) I would like it to output: /usr/lib/libblas.so.3gf=>/usr/lib/libblas/libblas.so.3gf.0 ...
3
votes
1answer
46 views

find files without extension

Let say I have: foo.txt bar baz.ooo If I use ls -1 !(*.*) then I'll get only bar on the output. Great, now I wish to have same results with find - some find -regex that will do the job. NOTE: ...
2
votes
1answer
41 views

Parameter substitution and error messages: suppressing line numbers etc

Here is my example file: !/bin/bash # argument-one # Is first argument missing? # First method [[ "$1" == "" ]] && echo "Usage: $(basename $0) filename"; exit 1 # Second method # ...
0
votes
0answers
32 views

Calculate Total disk i/o by a single process [duplicate]

I am looking for some tool that will dump total disk I/O by a single process after it ends. So far my finding is :- iotop= It shows i/o per process in real time but does not give total after process ...
0
votes
1answer
35 views

Syntax error in bash script: near unexpected token `else' [closed]

#!/bin/bash input="" echo "Does a wall needs to be sent?" read input if [ $input="yes" ]; then echo "Sending message to all users" echo "" else if [ $input="no"]; then exit fi fi echo ...
2
votes
3answers
41 views

bash - extract filenames from html file containing multiple links

I have downloaded an html file autogenerated by a script on a webpage. The file contains multiple links, including links to images I am trying to extract the full names of the images, for example ...
0
votes
0answers
21 views

-bash: android: command not found

I'm on a Mac running Mavericks trying to learn how to develop Android apps (in the process I'm learning bash too). To run on the emulator they suggest the command android avd. I always get the error ...
3
votes
3answers
112 views

Is the output mixed like this because of xargs and how can I fix it?

I'm learning a bit of Bash by using xargs to list whois records for a bunch of IP addresses. The command used is: echo "$1" | tr "\n" "\0" | xargs -0 -n 1 -t -P 3 -I % sh -c 'echo "\n 44rBegin whois ...
3
votes
2answers
27 views

Comparing an string by value of a floating number to a number

I wrote the code below: for j in `cat output_10.txt` do dri=`echo $j |cut -d':' -f1` nu=`echo $j |cut -d':' -f2` tot=`echo $j |cut -d':' -f3` fre=`echo $j |cut -d':' -f4` if [ $fre > 2 ] ...
1
vote
2answers
46 views

Merge csv files with conditions

I have 2 CSV files for each date (csv_2014_4_15 and csv_2014_4_16) , with basic structure and couple of unique columns as below. id,name,created_at,updated_at,other columns 12, joe, 2013-1-1 18:30, ...
1
vote
1answer
22 views

How to slice a text file into several files of 100 lines each? [duplicate]

My question might be quite unclear here. I have a giant text file with values that looks like this 0.00601233 0.000139403 0.000133679 0.000139497 0.000141683 0.000141888 0.000138646 0.000133465 ...
2
votes
3answers
142 views

in bash, read after a pipe is not setting values

Edit : original title was "read fails in bash" With ksh I'm using read as a convenient way to separate values: $ echo 1 2 3 4 5 | read a b dump $ echo $b $a 2 1 $ But it fails in bash : ...
3
votes
1answer
29 views

Why does the read command not take interactive options when run by sh?

I want to download a provisioning script that reads some configuration parameters via read, and execute it: curl http://example.com/provisioning.sh | sh The problem is, that the read command in the ...
3
votes
2answers
128 views

using “ifne” in Bash pipe

In my script, I am using the ifne utility from the moreutils package. The line can be simplified to the following: printf "asdf\n" | ifne cat - && echo "stream not empty" ifne only ...
2
votes
2answers
20 views

Writing content from a file to another file on set time intervals using delimiters

I'm trying to write a script in bash that reads a file file1 and writes to another file file2 every 2 seconds, which is easy enough. However, I want to write to file2 on either a line by line basis ...
2
votes
1answer
28 views

Controlling bash script concurrency, flock inheritance

I have a bash deployment script that handles deploying updated code to a Tomcat instance on CentOS, however, both Chef and RunDeck may invoke the script, and since Chef runs periodically there is a ...
1
vote
1answer
38 views

Why does the same sed regex (after grep) fail when run in a bash script vs bash command line?

Here's the script. It is successful when I run it from the BASH prompt, but not in the script. Any ideas? When I say "fails," I mean the sed regex doesn't match anything, so there is no replaced ...
10
votes
3answers
587 views

Is there any major difference when comparing a variable as a string or as an int

Out of curiosity, when doing a bash variable comparison (its value being an integer) it's possible to test it against some predefined value either declared as an int or as a string. Sample script: ...
0
votes
2answers
55 views

How to count number of instance of a word starting at another word

I need to grep the MySQL-error log starting at today's date formatted like: `date +"%y%m%d"` (140710) And look for all instances of the word partitioned. I've tried various things to no avail. ...
1
vote
0answers
37 views

Sourcing nested sourced bash script multiple times causes an infinite loop [closed]

I have a cronjob that sources a configuration file, so as to put some variables in the environment, and then runs a script. This config script sources another more general config file that sources ...
4
votes
3answers
145 views

Adding comments using 'set -x'

Sometimes it is really handy to just add set -x to the top of your script to show all commands before they are executed. There is only one drawback creating scripts with a decent output: I don't ...
3
votes
6answers
122 views

ls content of a directory ignoring symlinks

I have a directory in which I would like to list all the content (files and sub directories) without showing the symbolic links. I am using GNU utilities on Linux. The ls version is 8.13. Example: ...
1
vote
2answers
54 views

Configure bash and/or vim to execute source ~/.bashrc everytime I finish editing it

I would like to execute source ~/.bashrc every time I finish editing a file with vim (i.e. after :wq vim command). How should I configure vim or bash to work that way?
1
vote
1answer
54 views

Searching history forward after backward?

In bash, when I hit Ctrlr, I can search the command history backward. If I would like to search forward again, what shall I do? I hit Ctrls, but it doesn't work. My bash is GNU bash, version ...
1
vote
3answers
56 views

sed - replace string with file contents

I have two files: file1 and file2. file1 has the following contents: --- host: "localhost" port: 3000 reporter_type: "zookeeper" zk_hosts: - "localhost:2181" file2 contains an IP ...
5
votes
4answers
88 views

Have xargs use alias instead of binary

Bash 4.2 on CentOS 6.5: In my ~/.bash_profile I have a bunch of aliases, including: alias grep='grep -n --color=always' so that I can get color highlighting and print line numbers automatically ...
1
vote
3answers
80 views

How to escape special characters in a string?

Assuming $file holding a value of a file name, say Dr' A.tif. In bash programming, how could I escape single quote and any other special character of the $file without removing the special character? ...
3
votes
1answer
30 views

Matching several patterns on one line

I often use a program called tty0tty, which creates a null modem using PTYs. Now I want to make it part of an automated process. When I start tty0tty it prints (/dev/pts/1) <=> (/dev/pts/2) ...
2
votes
1answer
29 views

Using xargs with git

I am trying to practice using xargs. I tried the following, passing the SHA1 via xargs: $ git show SHA1 --name-only I also tried: $ git log --author=jim --grep="patch" |head -n 1|cut -d ' ' ...
2
votes
1answer
69 views

Bash script and processes

I have created a bash script for use with a graphical bar in Linux, however the script seems to spawn too many processes. The script: #!/usr/bin/bash executable="/usr/local/bin/bar" monitor=${1:-0} ...
1
vote
1answer
35 views

Control + L not clearing screen

When I try to clear my terminal screen on OSX: computer@ ~ () $ ^L And when I hit Enter after that it just shows: -bash: : command not found Any ideas on how this happens? My .bash_profile, ...
4
votes
1answer
50 views

Create map network_iface_name <--> IPv4 address

I'd like to implement a bash script that creates a mapping between the network cards (or interfaces) names in my computer and their IP address (in CIDR format, if possible). The goal is having ...
5
votes
2answers
113 views

Is there a way to make this one-liner faster?

Context I have a directory of thousands of zip files that are dated in the form YYYYMMDD_hhmmss.zip and each about 300K. Within each zip file is about 400 xml files each about 3K. The problem I ...
2
votes
2answers
150 views

Store all dates in a given date range into a variable

I want to store all possible dates between two user input dates. The input will be as like 20140605 and 20140830. I want to store every date between the given dates into a variable using a loop so ...
6
votes
2answers
147 views

Batch rename image files by age plus add date and variable to filename

The question is completely rewritten due to things learned from the first two answers and comments that I was unaware of when first asking. After a photo shoot I come home with files that look like ...
2
votes
2answers
24 views

How can I quickly return back to the last working directory? [duplicate]

All too often I find myself cycling between two directories to perform different tasks. The directories don't always have an easy-to-use relative path between them. As a result it is quite cumbersome ...
2
votes
0answers
19 views

Running Custom commands in a Terminal Application [duplicate]

I'm running a terminal application in /dev/pts/X terminal that has its own console as:         What I need is to run commands specific to this application but from ...
2
votes
1answer
45 views

bash + Is there something like log4j for bash script?

Is there something like log4j for bash script? I would like to be able to treat errors differently based on their severity. For example, log4j allows me to differentiate between errors, info, debug, ...
3
votes
0answers
98 views

bash does not autocomplete my command when using sudo?

I'm using SaltStack. I would like to auto-complete the minion name when calling salt command. The following line has been added into ~/.bashrc: complete -o default -o nospace -W "$(sudo ls -1 ...