Bash is the shell from the GNU project. It is the standard shell on Linux and often available on other unices. If your question applies to all Bourne/POSIX-style shells, use the /shell tag instead.

learn more… | top users | synonyms

2
votes
1answer
29 views

Turning off default video output with xrandr when external monitor is connected

I'm new to bash scripting, and I'm trying to configure my video outputs so that my laptop display gets turned off when I connect an external monitor via VGA. That's the script I came up with, pretty ...
4
votes
4answers
149 views

Bash Scripting : Printing column data in the same row

I have written a bash script to calculate the size of a PostgreSQL database and print the output along with the date when the script was executed in a text file. The script code is as follows: ...
0
votes
3answers
54 views

Assigning a command to variable

I assign command ls to my variable my_File but when I run it as $my_File it does not work. Can you please explain why? #!/bin/bash my_File='ls -f | grep -v '\/'' $my_File
1
vote
1answer
49 views

How can I start tmux automatically in fish shell while connecting to remote server via ssh

I switched from bash to fish shell. I liked it and decided to use it on my servers also. How can I start tmux automatically on ssh connection? I followed this instruction for bash but fish shell is ...
10
votes
7answers
251 views

Test if multiple variables are set

I'd like to make sure that at a certain point of a script, after sourceing a configuration file, several variables are set and, if they are not, to stop execution, telling the user about the missing ...
6
votes
6answers
342 views

bash find lines starting with string

I have a bunch of files and I want to find which one contains sequential lines starting with a certain string. For example for the following file : Aaaaaaaaaaaa Baaaaaaaaaaa Cxxxxxxxxx Cyyyyyyyyy ...
0
votes
1answer
76 views

ssh with for loop - parentheses problem

I have the following script: while [ "$1" != "" ] do case "$1" in -h) HOST="$2"; shift 2;; esac done if test -z "$HOST" then [...] else TODAY=$(date +'%Y-%m-%d') ...
0
votes
2answers
81 views

Alternate option field

In a script i have a list of options that needs to be entered by the user. They are -c cell name -> it must be there -n node -> it must be there -s server -> it must be there Uptill here its all ...
4
votes
2answers
109 views

Convert every pdf in the current directory to png

I want to write a bash script to convert every .pdf file in the current directory into a .png file. For example: $ls . a.pdf b.pdf $./pdf2png.sh Converting pdfs to pngs a.pdf -> a.png b.pdf -> ...
1
vote
2answers
29 views

Why my tabs are not expanding in TIMEFORMAT?

I need to measure the running time of an application, so I'm messing with TIMEFORMAT in order to print short format with the maximum precision available. From the Bash Refence Manual: TIMEFORMAT ...
2
votes
3answers
63 views

purpose of run-parts(8) utility

At least under Debian-based systems, there is a run-parts utility in debianutils package which is used in various scripts. For example in /etc/X11/Xsession. It will run all the executable files found ...
2
votes
5answers
288 views

How to reverse a string made of digit in bash?

What is the best way to turn out digits in number? E.g. $ echo 123 | hook 321 $ echo 12358 | hook 85321
1
vote
2answers
54 views

difference between “ls –alR /” and “ls –alR / &”? [duplicate]

What is the difference between "ls –alR /" and "ls –alR / &"? I seem to get the same out put. but the & sign i think should run it in background?
2
votes
4answers
86 views

bash script and local env variable namespace collision

I have a bash script with a variable called VAR_A I also have a local env variable called VAR_A The bash script calls the command: echo ${VAR_A} I am not able to change the variable in the script ...
0
votes
0answers
28 views

AiX topas snapshot to web

My script for taking snapshot from TOPAS looks like this: #!/usr/bin/bash whoami export TERM="xterm" (sleep 3; echo q)| topas -Emi 2 | \ tr -d '\r' | \ ...
3
votes
2answers
40 views

Bash script : help file inside the script or in a different file?

I'm writing a script that has the vocation to be a fully featured program at the end. As far as I know, BASH is enough for his purpose (manage PPA's, kinda like Y-PPA). I would like to know how to ...
1
vote
2answers
44 views

Bash script is not working

I wanted to create a script that executes the ls command with the provided arguments. Why isn't it working? I tried running it with for example -R, then it echoes (I echoed the same thing for ...
0
votes
1answer
41 views

How to display data in columns in two variables with the same format?

I coded the following to display data formatted in columns: str1='hello i am robert and your ma frnd' str2='thisisaverylongword thisistoohehehe andherefinishthe string hereis a other ...
2
votes
2answers
50 views

I want a script which will take multiple column numbers from a user and reverse the contents

I want a Unix script which will take multiple column numbers from the user and reverse the contents. declare -a param="$@" # enter 0 when exit the insert element echo "Enter the numbers" read n while ...
2
votes
1answer
63 views

Window title in X shows wrong application name

I am using LXDE environment in Debian, but I think my question is general. When I have a window opened (i.e. terminal emulator running bash) the window has a window title with the text /bin/bash. When ...
5
votes
4answers
169 views

Run a command when system is idle and when is active again

I want to run a command when the user becomes inactive (the system is idle). For example: echo "You started to be inactive." Also, when the user becomes active again (the system is not idle ...
-1
votes
1answer
84 views

How to use adduser command with a bash script

I'm trying to find the way to use adduser this way: adduser $username $password or something like this too: adduser -u $username -p $password I know I could use useradd and so, but right now I ...
2
votes
4answers
171 views

Running bash script on a remote Windows Machine

I am planning to run a bash script on a remote Windows system from my local Linux machine. For this purpose, I will have to log in to Windows machine from the local one and then execute the bash ...
2
votes
4answers
77 views

How Can I Change the Default arguments to gcc When I run Make “filename”

Forgive me if I posted this in the wrong Stack. Every time I run make for a file without any Makefiles in the directory, make still works and compiles the source code but only with the arguments: gcc ...
2
votes
2answers
124 views

Assign value to a variable in bash, coming from another commands

Doing this in bash, makes SUFFIX variable holding /dev/fd/[fd], SUFFIX=<( echo "&*645\[]}#@name" | sed -r 's/[^[:alnum:]]+/_/g' ) What should I do to assign the actual result, of commands ...
1
vote
1answer
55 views

Not able to copy multiple files using rsync 3.0.9 version?

I am trying to copy two files using rsync from a machineB but somehow it always copies only one file but not the second file - Here is the syntax I am using - rsync -avz ...
2
votes
1answer
87 views

Bash Script getting stuck during execution

I have a bash script that is reading a CSV file , that contains source IP address , destination IP address and destination port. My script is basically doing 2 tests: 1 Performance 2 Connectivity. ...
4
votes
2answers
226 views

Merge fields in a file

I have a file with 7 columns, a GFF file having chromosomal regions.I want to collapse the rows where REGION ="exon" to only one row in the file.The row has to be collapsed on the basis of regions ...
2
votes
2answers
27 views

Setting tabstop for bash output

Is it possible to set a tabstop (number of spaces per tab) for the more and less commands? In vi, I've added this line to .vimrc set tabstop=4 However when I read through a file with more it still ...
4
votes
6answers
129 views

List all binaries from $PATH

Is there one-liner that will list all executables from $PATH in bash.
0
votes
2answers
41 views

Reversing 1-D array

I'm trying to reverse a 1-D array which contains a list of files. I followed http://stackoverflow.com/questions/13360091/how-to-reverse-array-in-bash-onliner-for-loop to be the code. But this is not ...
1
vote
1answer
20 views

Using 'find' to email me those files modified recently

I'm using 'find' at the end of a script to email me any .log files in the current directory that have been modified in the last 6 hours. I need this because the file names change so I can't be any ...
2
votes
4answers
101 views

Parsing process command-line arguments from pargs in a shell script

I get list of PIDs in my bash scripts (Java processes) and have to analyze their command-line arguments to determine which instance of server each PID corresponds to. At the moment I do it that way ...
4
votes
2answers
206 views

Concatenate all commentary about source files in a directory tree

I am working on a multitude of projects involving codes in Fortran. They are in a directory tree involving 10 to 20 folders, each of the codes is in a 'src' folder. What I am looking for is a simple ...
-2
votes
1answer
46 views

Using If statment [closed]

I'm trying to use an If/else statement in bash. I'm confused which is the correct syntax. if [ "$NUMBER_dcn" -gt $NO ] then dir_dcn='/mnt/md0/capture' fi or if [ "{$NUMBER_dcn}" -gt ...
0
votes
2answers
42 views

Running Commands on Remote Linux Server Using SSH

I am writing a Bash Script wherein I need to run some set of commands on a remote Linux server from my local computer using SSH. I want the results to be displayed on the terminal screen or dump the ...
-2
votes
2answers
62 views

Run command automatically after login?

Another quick question. I have installed f.lux on Ubuntu 12.04, however the program refuses to work unless I run a command xflux -l [longitude] -g [latitute] -k [temperature] So I've created an ...
3
votes
2answers
91 views

Execute bash commands over SSH while staying in interactive mode afterwards

Probably it is a weird thing I would like to achieve but: I would like to SSH to a remote host and then execute some bash commands like "alias" automatically to use them afterwards in an interactive ...
3
votes
1answer
42 views

Bash tab completion stop searching

When I am typing into bash and I press the "tab" key to auto complete, sometimes it takes a significant time. E.g., file IO to read directories takes >5 seconds, and thus I am hung waiting for IO to ...
5
votes
1answer
111 views

understanding the default value of IFS

In my GNU bash version 4.2.8, IFS has a default value of space, tab and line feed by default: usr@T42 ~ $ echo -n "$IFS" | hexdump -C 00000000 20 09 0a | ..| ...
2
votes
3answers
148 views

How to use rsync or scp to efficiently copy the files from machineB and machineC to machineA?

I am running my shell script on machineA which copies the files from machineB and machineC to machineA. If the file is not there in machineB, then it should be there in machineC for sure. So I will ...
3
votes
1answer
86 views

What does exec 3<&1 do?

I understand exec can do I/O Redirection on current shell level. but I only sees usage like exec 6<&0 # Link file descriptor #6 with stdin. # Saves stdin. exec 6>&1 # ...
8
votes
3answers
144 views

How to define similar bash function at once

I have these functions in ~/.bashrc: function guard() { if [ -e 'Gemfile' ]; then bundle exec guard "$@" else command guard "$@" fi } function rspec() { if [ -e 'Gemfile' ]; ...
1
vote
2answers
77 views

How to find out all the files in other machines using bash shell script?

I am trying to find out which files are in machineB and which files are in machineC. And I need to run my shell script on machineA to figure out which files are in machineB and which files are in ...
4
votes
3answers
100 views

How can I pass argument stored on a variable to WGET

I'm writing a bash script that extensively uses wget. To define all common parameters in one place I store them on variables. Here's a piece of code: useragent='--user-agent="Mozilla/5.0 (Windows NT ...
3
votes
2answers
141 views

Set difference from two files in unix

I am looking for an efficient way to achieve set difference from 2 files. I do know that grep -vxF -f setA setB gives me B - A. This is what I want, but my files are as follows: setA: 2 4 5 6 set B: ...
1
vote
2answers
41 views

create file from function

#!/bin/bash # trims trailing spaces and tabs from file, using awk utility function remove_trail() { [ ! $# -lt 2 ] || { echo "Usage: $FUNCNAME file-to-trim out-file"; return 1; } # args ...
3
votes
1answer
33 views

grepping with “shopt -s globstar extglob”

I have shopt -s globstar extglob in my ./bashrc. I'm searching for files that refer to string Foo in the following command: grep -Fwn Foo /**/src/**/*.@(h|cpp) Now I want to except all refers from ...
1
vote
4answers
52 views

Write program output to log file containing PID in its name

How can I start a program and write its output to a log file, where the log file contains the PID in its name? I tried program_a > log_$! which doesn't work since $! is the PID of the last ...
4
votes
2answers
61 views

Brace compression

I love brace expansion (e.g. rm file.{0..5}). I find it a lot easier to read than the expanded version. Is there a quick and easy way of doing the opposite? For example given the input ...