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
1answer
26 views

Calling bash getopts from a function fails the 2nd time

I'm trying to parse arguments passed to a bash function using getopts inside that function. It works when the function is called for the first time but fails on all subsequent calls. Here is a simple ...
5
votes
3answers
263 views

What does `. /path/command` do? (Space after dot, absolute path)

From this guide to Bash completion we learn that in order for Bash to perform auto-completion one must perform . /etc/etc/bash_completion.d/foobar (note the space after .) in order for Bash completion ...
2
votes
3answers
19 views

Append and write out variable-named file from list of variables

I would like to create multiple 'wget' shell scripts to download a batch of considerably large (~3GB) files using our HPC cluster. The names of the files are stored in filenames.txt, like so: $cat ...
3
votes
1answer
95 views

What does . ~/.bashrc command do? [duplicate]

I was viewing my .bash_profile file, and I saw this written inside a block of if statement: if [ -f ~/.bashrc ]; then . ~/.bashrc Can someone explain what the second line is actually doing? ...
2
votes
1answer
21 views

Intercept and modify commands in bash scripts

I have some scripts and some commands in the scripts are like this ./executable arg1 arg2 .. argn I want to change the above command to LD_PRELOAD=/some/lib ./executable my_arg1 my_argn arg1 arg2 ...
1
vote
2answers
91 views

How to lock screen for a terminal session?

as we could use xflock4 command to lock the screen (ask for a password to continue) in an X session; I need a similar way to lock the tty1 session. Is there any? (logout is not working when I call in ...
3
votes
2answers
40 views

Execute command after inotifywait established watches

Inside shell script (test.sh) I have inotifywait monitoring recursively some direcotry - "somedir": #!/bin/sh inotifywait -r -m -e close_write "somedir" | while read f; do echo "$f hi"; done When I ...
3
votes
2answers
98 views

Capture in shell variables the arguments after a command (between brackets)

Suppose I have a file that contains, among many other things, \command{arg1,arg2,arg3} (arguments been paths, expressed with /, ., characters and numbers) But that a user can as well call it ...
0
votes
2answers
41 views

ps output / pipeline execution order

I run ps aux | grep somethinghere. The output shows the grep somethinghere as a running process. My question is, shouldn't ps aux finish first, then grep somethinghere run on its output? Maybe there ...
0
votes
1answer
13 views

Resizing Whiptail to full terminal screen

How to make whiptail full terminal screen? "as big as the terminal", like fluid CSS, something like 100%
1
vote
0answers
26 views

Questions about whiptail and bash functions

I'm a bash newbie. Say I have this script #!/bin/bash function cpp-lang { yum install "Development Tools" } function updatesys { yum -y update yum -y upgrade } whiptail ...
0
votes
1answer
12 views

What port uses my backportpackage or bzr?

I am working in a company what uses Ubuntu Precise on the desktops behind a proxy. The Proxy is available in /etc/environment and set as: http_proxy, https_proxy, ftp_proxy, no proxy and their ...
0
votes
1answer
48 views

Bash escaping is confusing me

Lets say that I have a file (executable) called literally 'a\b'. It just echoes some stuff. Now I want to call that and I can do it by inputting user@machine:~/test$ ./a\\b into my console. Now ...
0
votes
1answer
16 views

Redirect all bash script output (from inside the script) to two files: one append, one rewrite; but discard output to the console

I can easily redirect both standard and error output of a bash script to the file, while discarding an output to console with simple exec statement: exec &>>/var/log/backup.log But how do ...
1
vote
1answer
40 views

Whats wrong in creating/printing this array?

To find the average time taken to create certain files, I'm using this minutes array, then would simply use bash arithmetic to find the average. However I'm unable to get the difference except for the ...
0
votes
1answer
29 views

vim - “Press ENTER or type command to continue” right after loading only?

Recently my vim has developed the habit of displaying Press ENTER or type command to continue the first time I do certain things right after I open it. For example, if I'm at my shell prompt and type ...
0
votes
2answers
27 views

process substitution for opening a list of files with an application

I wish to use process substitution to direct a list of files (produced, for example, by ls or find) to a particular application for opening/viewing. While piping such a list to xargs is suitable for a ...
3
votes
1answer
65 views

Unix: Bash Limiting Output to X Amount of Lines

I am trying to modify a script so that it will truncate the output that goes to another file to a maximum (for example: 1000 lines). I have read about split, but what I understand is that split by ...
0
votes
1answer
22 views

Setting up a script on an AMI box to create directories - vsftpd, pam, mysql

I'd like to first say I'm a noob when it comes to linux, so please excuse my confusion. I'm trying to setup vsftpd on a amazon ami 64 bit box, free tier micro. Following these instructions, ...
2
votes
2answers
243 views

How do I use a function return as a condition of an if else then shortcut?

There are instances where a function needs to execute and return to the caller and this works for me. if tst; then echo "success" else echo "failure" fi function tst () { return 0; } ...
1
vote
0answers
10 views

java version not found in redhat

My OS is redhat linux. It's having the default java 1.4.2, but I need java 1.7.45, for that I am trying as follows: /usr/sbin/alternatives --install /usr/bin/java java /u01/java7/bin/java 5 ...
2
votes
3answers
132 views

Loop over associative arrays by substring

In the following code, I create some associative arrays in a loop. The consist of two strings, a string identifier and a year. After creation, I want to access the arrays in a loop based on the ...
0
votes
2answers
32 views

Locate specific file from script

I've written a script file in which, one function searches for another script and if found, executes that script. Script extract #!/bin/bash ... service_status() { local my_script=`which ...
2
votes
1answer
18 views

Strange characters in GIT completion

I'm running bash GNU bash, version 4.3.25(1)-release (x86_64-apple-darwin13.4.0) on OS X 10.10.1. A week or so ago I've noticed that autocompletion has stopped working, but only for git. I'm ...
1
vote
1answer
25 views

Broken git autocompletion after I have overridden the git command

Recently git branch <tab> started showing me the following error: $ git branch bash: -c: line 0: syntax error near unexpected token `(' bash: -c: line 0: `/usr/bin/git --git-dir=.git ...
0
votes
1answer
25 views

Error while running script with nohup

I got this error while running my script with nohup sh: syntax error near unexpected token `(' My script is as follow: #!/bin/bash report_log="report.log"; grep -A 3 'successful\|ERROR COUNT ...
1
vote
2answers
40 views

script that lists all files in a directory and subdirectories sorted by size, listing only file names not complete paths

I'm looking for a script that lists all files in a directory and subdirectories sorted by size, listing only file names not complete paths. find . -type f -exec ls -lhS {} \+ works but gives the ...
5
votes
1answer
29 views

Using process substitution to trick programs expecting files, with specific extensions as argument?

Here is my use case: the command line utility melt can accept a file name, with the extension .melt on the command line, and open it; as an example, this is a proper test_p.melt file: colour:blue ...
2
votes
2answers
34 views

how to workaround a deadlock (multithreading a program)

I need to run a program 100 times, a few hours each, which is fine when running it in a serial way, just takes very long, but when I try to parallelize it using GNU parallel or simple '&' in bash, ...
-5
votes
2answers
34 views

placing things in a users home directory with .deb

i am making a .deb installer and would like to place some files in the users home directory but i can not hard code a username. does any one know of any other places in the file system that i could ...
0
votes
1answer
36 views

finding and replacing text [duplicate]

Does any one know how to find and replace text in a file. it can be implimented into a bash file. i would like to find the line and the output the text to it the file can only be opened with the root ...
0
votes
0answers
17 views

bash/svn how to filter documents [on hold]

Does anyone know how to filter documents. For example, if I had something like this: dVa/Prs/Upe/dVar.var I want to only the last file in log and then add to this file another for example after ...
0
votes
1answer
17 views

Unix: Looking to run a script in directories with a certain name

I am writing a script in bash. If I am in directory Foo, I want to run this script in only the subdirectories of foo that are named foo with up to three numbers after foo. Ex: foo1, foo23, foo345 ...
2
votes
1answer
64 views

Bash: command substitution with multiple unset/export commands

I am trying to unset some variables and export others using command substitution. This works: $(echo " export TEST_A=1 export TEST_B=2 ") And this too: $(echo " unset TEST_A ...
3
votes
3answers
70 views

The output I get via “echo” works as a command when pasted to terminal, but not in the script

I'm trying to change the files generated by an app that unfortunately often contain spaces. I have managed to get "echo" to give me output that works if copy pasted into terminal, but when I try to do ...
0
votes
2answers
27 views

Command substitution and spaces

Why does this work as a calculator: [root@qabun02 ~]# echo $(( 5+2 )) 7 but this doesn't? [root@qabun02 ~]# echo $( (5+2) ) -bash: 5+2: command not found The only difference I can see is the ...
0
votes
1answer
20 views

Bash script: array elements containing space character [duplicate]

I'm getting started with bash scripting. I'm working with array elements that contain space characters. In the code below, the third array element is "Accessory Engine". I tried to set the space ...
1
vote
1answer
75 views

Why does the printf statement in this loop output the array out of sequence?

When I execute the following code, the output of the printf statement appears to show array out of sequence. In the declare statement the Source item is declared before Destination and in the output ...
3
votes
1answer
49 views

Can I run a command loaded from .bashrc with sudo?

I have some custom functions and aliases defined in my .bashrc file. Sometimes I need to execute whem as root. I then do something like: $ sudo custom_cmd 80 ...
0
votes
2answers
60 views

How to convert Log file to CSV using bash

Is it possible to turn this log entry into a properly formatted csv file using sed/awk? I've tried multiple ways to do this using sed/awk. Alas I couldn't do it. Before I do it in perl. is this ...
2
votes
3answers
60 views

How to get tab completion when using curly braces in Bash

I want to have tab completion when using curly braces in a command in bash. For example: cp ~/html/{foo bar.txt whatever} /var/www/html/ I want the tab completion for the files stated in the curly ...
2
votes
3answers
72 views

Using find with 2 sets of variables

I want to be able to run a find command in my bash script that will find files based on two seperate variables. I've gotten this far but I'm not sure how to get the final result workingfind . -user ...
0
votes
2answers
53 views

Untar and gzip from multiple sub directories

I have a directory which consists of multiple sub-directories. Each subdirectory has a tar.gz file which on untar gives two files namely R1.fastq and R2.fastq. I want to untar the tar file and ...
0
votes
1answer
35 views

Opening a socket in Kali Linux using bash scripts

I know how to open a TCP or UDP socket in Ubuntu, with the following command : exec 3<>/dev/tcp/google.com/80 for example: we can open a TCP socket on port 80, but in Kali Linux there's no ...
1
vote
1answer
42 views

Read a character from an x-y coordinate on the screen

Is there a way in bash to read a character from an x-y coordinate on the screen? This command would be something similar to cget 12 30 which would return the character at the 12th row and 30th ...
0
votes
2answers
24 views

redirect output from interface?

I am echoing an AT command to a modem interface (/dev/ttyUSB3) and the command runs successfully. For instance the below command works and has an output of OK: echo -e "ATZ\r" > /dev/ttyUSB3 I ...
0
votes
2answers
22 views

The best way to add Unix Shell variables to CURL GET request

Let’s say I use curl –X GET command with the following link: “$WEBSITE_URL/ACTION_NAME/ACTION1;id=$ID?Command=TEST&id1=$ID1&id2=$ID2&id3=$ID3” As you can see, there are some $variables ...
0
votes
1answer
33 views

I don't see .bashrc file in my /home and /etc/skel direcories

I am running linux mint 17.1 rebecca, but I have found it quite different with other distros I am used to, in /home and /etc/skel there's no .bashrc I don't know if i mess up with something or it is ...
0
votes
1answer
18 views

Tar Create and Split files into subdir

I have this command: tar -cf - input/* | split --bytes=1m Which splits my huge gz files into small ones. This works fine. However I want the output (the small files) to be created in the input/ ...
0
votes
1answer
14 views

Universal .bashrc alias showing results of sysytemctl start command

This is small .bashrc alias that allows me to see results of starting service alias systemctl start apache='systemctl start apache && echo SUCCESS || echo failure' How can i modify to work ...