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

1
vote
4answers
234 views

How to set the process won't be terminated when the terminal stops

[Edit] Make it simple. I invoked java xxx... on Machine A using putty to connect from Machine B. However I cannot reach Machine B. How can I connect Machine A from Machine C to set the running ...
1
vote
1answer
1k views

Interpret an interpolated variable as a literal string in Perl regex

I am using perl to colorize a matched string MATCH=aaa printf "aaa\n/dev/aaa\nccc\n" | perl -pe "s/($MATCH)/\e[1;31m\1\e[0m/g" This works well until I try to match a string containing special ...
1
vote
1answer
309 views

Check SSE3 support from bash?

Is there a way to check whether or not the current system supports SSE3 from a bash script? I'm currently writing an installer script, and the program in question has an alternate version that takes ...
1
vote
1answer
1k views

getting list of children processes by a background shell function

I have a bash script, in which I call function in a background: process_manager $1 $2 $3 & The function runs / executes commands that are passed as an argument in the background. How can I get ...
1
vote
1answer
491 views

getting pid of two last commands executed in background and do stuff

I wrote this bash: #!/bin/bash eval "(a command) &" pid1=$! eval "(while kill -0 $pid1; do .... ; done) &" #It creates file.txt after few seconds pid2=$! if [ -s ...
3
votes
2answers
513 views

How to find all paths not compatible with Windows?

On most Linux filesystems, NUL (\0) is the only invalid character in paths (and / is reserved as the path separator). Windows has a complicated set of rules for valid paths. Rather than fixing paths ...
2
votes
3answers
393 views

CTRL C behavior in hierarchy of shells

First of all sorry about terminology errors, I'd try to be clear. I open a shell (like sbt or node debug from my bash). Then inside this shell, I open another one (using scala or node repl ...
17
votes
2answers
6k views

Closing a file descriptor, >&- vs <&-

In the bash tutorial I am reading, it says that if you open a file descriptor for reading, i.e. exec 3< echolist Then you must close it like this, exec 3<&- However, if you open a file ...
78
votes
3answers
42k views

Why does my shell script choke on whitespace or other special characters?

Or, an introductory guide to robust filename handling and other string passing in shell scripts. I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some ...
0
votes
1answer
47 views

better use of find - rvm.sh

I am trying to find rvm.sh as I am receiving the infamous rvm is not a function error. The file in most linuxes is supposed to be at /etc/profile.d/rvm.sh However on opensuse it is not there so I ...
3
votes
5answers
2k views

Listing directories based on size from largest to smallest on single line

I can use the following command to get a list of directories and their sizes and sort them from largest to smallest (in the example I renamed the directories to numbers to make this easier to ...
0
votes
2answers
540 views

dhcp query to get IP by MAC

I am using CentOS 6.5 and Internet Systems Consortium DHCP Server 4.1.1-P1 I found this file /var/lib/dhcpd/dhcpd.leases but not simple to parse it in bash is there any way to get the online clients ...
0
votes
0answers
52 views

how to pass asterisk as a parameter to getopts [duplicate]

I wrote a shell scripts with getopts to take arguments. But I want to pass an asterisk as an argument, for example script -a"Hello * all" -b"Another argument" if I echo the -a argument from the ...
7
votes
2answers
530 views

Is there any way to undo a bash history modification?

By pressing up, I can go through previously entered commands. I've noticed though that if I modify one of them, that alters the history. For instance, if I type: echo a echo b echo c ...
1
vote
2answers
677 views

How to show specific lines from specific columns of a file

First off, I'm not allowed awk, sed or perl. For my assignment I was given a file of employee list: Marketing Ranjit Singh FULLEagles Dean Johnson Marketing Ken Whillans FULLEagles ...
1
vote
1answer
2k views

Finding all files containing a word and then counting the number of lines

I need to recursively find all files that contain a specific word and if the word exists in file I need to find out the number of lines in that file. I have been trying to use grep but I have been not ...
0
votes
2answers
1k views

Using regex in for loop

I'm looking to loop through a directory of files and match them with regex, then subsitute the appropriate character: #somefile.txt %somefile.txt >somefile.txt # arr=(\% \> \#) ;for f in *; do ...
1
vote
1answer
199 views

dialog and gauge + yesno widget

I'm trying an example of combining a yesno widget to modify the input of a gauge widget. But it fails. My code is: #!/bin/bash PCT=0;i=0 ( while [[ $PCT -le 100 ]] do cat <<EOF XXX $PCT el % es ...
3
votes
1answer
532 views

Why does this command to copy files in a for loop work in bash but not in zsh?

I'm trying to copy a bunch of files with the same name, but in different subdirectories, to a single directory, changing the names to ones based on the paths to the original files. I use a for loop ...
3
votes
3answers
7k views

'is a directory' error when trying to pass directory name into function

Note: I am a newbie to bash scripting In my bash script, I use find to get the folder names by wildcard: for i in $(find ${directory} -mindepth 1 -type d -name ${wildcard}); do stuff=doStuff ${i} ...
-1
votes
2answers
79 views

I have a cpp error on UNIX [closed]

Hans Lao@Hans ~ $ cd /home/ddscat130527/src Hans Lao@Hans /home/ddscat130527/src $ make ddscat cpp -P -traditional-cpp -Dsp ddprecision.f90 \ ddprecision_cpp.f90 make: cpp: Command not found ...
2
votes
1answer
410 views

Trying to compare a variable that is multiline in a if comparison

Here is the current file I am running: #!/bin/ksh -x export BIN_DIR="../../env" . $BIN_DIR/vdenv.ksh success="DROP CREATE TABLE GRANT" $worker_dir/runsql.ksh ddl X X > chnl_avt_v1.log ...
0
votes
1answer
164 views

Duplicate specific text in text file, using perl or grep

I need to duplicate part of a plain text file as follows: The text file consists of a sequence of "pages", of the form: <page [lots of lines of text] /page> <page [lots of ...
0
votes
1answer
175 views

How to know how long will my simulation run in UNIX?

I am new in using Unix, I want to know what command can display how long will my simulation run. I am using windows but running cygwin to get the UNIX environment. I am running a discrete dipole ...
1
vote
1answer
869 views

How to sync terminal session command history in bash?

I've tried to search in ~/.bash_history for my recent commands while in a terminal session but they just weren't there. I guess this is because I have multiple terminal sessions open. Is there a way ...
4
votes
2answers
4k views

Is there a GUI debugger for shell scripts

Debugging bash scripts on command line is complicated. Is there a good GUI based debugger available for debugging bash scripts?
0
votes
1answer
76 views

skip line that doesn't contain a particular character eg .colon

I am reading lines from a file in a while-loop. while read line do #process line done I want to skip lines that do not contain a colon.
6
votes
1answer
247 views

Highlighting text in bash when using reverse history search using Ctrl-R

Using Ctrl-R, I can search the history in bash. But what to do, If I want to highlight the relevant word which has been typed upon by me. Example: (reverse-i-search)`mount': sudo mount /dev/sda2 ...
0
votes
1answer
83 views

egrep part required for svn hook script

I am trying to write a pre commit hook script to Enforcing tag naming convention like < application>_ < project >_ < version>_ < iteration> this using a shell script can anyone ...
2
votes
1answer
463 views

Commands run when terminal is open do not appear in history

I have the simple following terminal.sh script: #bin/bash --login str=(--tab --title="Test" -e "bash --login -c 'echo history';bash") gnome-terminal "${str[@]}" exit 0 I basically use it to open a ...
4
votes
2answers
196 views

Falling to git checkout on non-found bash commands

When I type (in bash) a command which linux does not find, it usually does something like this: $ x x: command not found but when I type a command which is not found but which is similar in some ...
1
vote
1answer
212 views

How to copy in two folders simultaneously using GNU parallel by spawning multiple threads?

I am trying to copy files from machineB and machineC into machineA as I am running my below shell script on machineA. If the files is not there in machineB then it should be there in machineC for ...
1
vote
1answer
4k views

Proper escaping of double quotations for curl post data?

I'm trying to test out a server, by sending it JSON data and reading the response. I need to POST data like {"item":"value with spaces"} but when I use curl I find that it sends the backslashes as ...
9
votes
2answers
22k views

How to move a file without preserving permissions

The problem is I want to be able to see errors when moving a file, but not see errors with permissions problem. In other words - I care if the file is not fully transmitted, but don't want to see ...
4
votes
1answer
112 views

Memory consumption of a script

Is there way to check the memory (physical & virtual) consumption of a script, of course in the moment of its execution. Calculating the used memory minus the used memory before and after the ...
9
votes
2answers
782 views

bash: is it safe to eval $BASH_COMMAND?

I am working on a shell script that constructs a complex command from variables, e.g. like this (with a technique that I've learned from the Bash FAQ): #!/bin/bash SOME_ARG="abc" ANOTHER_ARG="def" ...
2
votes
3answers
5k views

How to copy or read the return value (exit status) from AWK script into the shell script (bash) to be used in if statement to compare

I want to read the error codes or the exit status of awk script into shell to use in if condition to compare for error handling my shell script looks something like: My script: #!/bin/sh awk -v ...
0
votes
1answer
126 views

Is there a command which displays options like `errexit` and `braceexpand` other than `help set`?

If you type help set, then - among other things - a list of shell options is displayed. But these options are not the same as those displayed with shopt. And different also from those displayed with ...
1
vote
1answer
1k views

ssh script asks for password

a little ssh issue here. I set up some keys in ssh between 2 machines and I can login via ssh without password in terminal. I am trying to write a shell script that sends commands to the remote ...
3
votes
2answers
1k views

dialog, trap and SIGTRAP

I've seen a lot of examples using dialog tools into scripts with lines as follows: trap "rm $datafile" 0 1 2 5 15 What I don't understand is the meaning of SIGNAL 5, ok I know is SIGTRAP. But shame ...
0
votes
2answers
676 views

Formatting numbers using awk / print

I found this very cool code to get upload/download speed: awk '{ if (l1) { print "↓"($2-l1)/1024"kB/s ","↑"($10-l2)/1024"kB/s" } else { l1=$2; l2=$10; } }' <(grep wlan0 ...
4
votes
2answers
149 views

Is there a workaround for Debian file-completion trashing $_?

I have years of experience on Slackware linux, and have never seen this problem there. Lately I have been administering Debian servers, and this has become an annoyance. I frequently use "$_" in a ...
5
votes
1answer
605 views

BASH_ENV and cron jobs

I have several questions related to non-interactive, non-login shells and cron jobs. Q1. I have read that non-interactive, non-login shells only "load" $BASH_ENV. What does this exactly mean? Does ...
4
votes
1answer
173 views

Why do bash variables disappear when I use xargs?

I have a simple bash script and want to count how often a command gets called. Here is a minimal example, the counter is called c and should be 4 at the end: #!/bin/bash c=0; for a in X Y; do for ...
1
vote
1answer
133 views

Play last few seconds of mp3

Is there any way to play last N seconds of an mp3 file on bash commandline?
3
votes
3answers
12k views

How to launch two threads in bash shell script?

I am trying to copy files from machineB and machineC into machineA as I am running my below shell script on machineA. If the files is not there in machineB then it should be there in machineC for ...
3
votes
2answers
4k views

find the single largest file

We host a share of size 4 TB. How efficient is it to find a file with highest size. Usually we use: du -ak | sort -k1 -bn | tail -1 and it is not easy to scan through a share of such huge size and ...
2
votes
1answer
629 views

bash not reading $TERMINFO on login (over SSH)

I have a OpenVZ Fedora 20 VPS that when I SSH into, my termcap file stored in $XDG_DATA_HOME/terminfo/x/xterm-termite, isn't being read, despite having TERMINFO=$XDG_DATA_HOME/terminfo set. If I ...
3
votes
5answers
5k views

Getting pid of bash script from itself

I have a bash script with doing lot of things called script.sh: #!/bin/bash #It #Is #Doing #Things Is there a way that I be able to get the proccess of script and then kill it after 5 minutes? ...
3
votes
1answer
255 views

Difference between “.” and “./” while setting the environment variables using export? [duplicate]

Please excuse me if I am not clear while asking questions. I will try my best to be very clear while asking questions. While learning Embedded Linux, we are setting an environment for our project. ...