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

2
votes
3answers
56 views

at job seems to be running using /bin/sh though I have a #!/bin/bash

I am trying to run a job using at, and I have a bash script (I do have #!/bin/bash as the first line), but the job fails because of use of [[ and ]] in the script, I see the following in the mail that ...
2
votes
3answers
139 views

Saving individual output lines into variables

I'm using find -mtime -2 to find files modified in the past 24 hours or less. The output looks like this. /home/user/logs/file-2014-08-22.log /home/user/logs/file-2014-08-23.log I need to save the ...
1
vote
1answer
40 views

Copy newest file in directory over SSH

How might one copy the newest text file from a particular directory on a remote server to his local machine? On the server itself I can do the following: $ cat `cd /home/user/dir ; readlink -f $(ls ...
2
votes
2answers
100 views

Why does Bash's “source” command behave differently when called from a function?

Given the following sourceable bar Bash script ... echo :$#:"$@": ... and the following executable foo Bash script: echo -n source bar: source bar echo -n source bar foo: source bar foo function ...
1
vote
1answer
65 views

How does bash execute an ELF file?

When I'm on my Linux Box I use bash as a shell. Now I wondered how bash handles the execution of an ELF file, that is when I type ./program and program is an ELF file. I grepped the bash-4.3.tar.gz, ...
2
votes
1answer
188 views

Running sh script: «Permission denied» despite the executable bit and root rights

I installed Debian in VirtualBox (for various experiments which usually broke my system) and tried to launch the VirtualBox guest addon script. I logged in as root and tried to launch autorun.sh, but ...
-3
votes
0answers
46 views

please let me know where to attach the files here? [closed]

Below is the requirement. Ignore lines containing pattern "SET SNAP_ID" or "Shadow Copy Components:\" . Ignore lines with column 2 till 8 is empty. print lines containing pattern "Failed". ...
6
votes
1answer
75 views

Getting wrong $LINENO for a trapped function

I am writing a Bash script for myself to learn scripting. At some point, I need to add trap in order to clean unwanted directories and files if script is killed. However, for some reason I do not ...
2
votes
3answers
70 views

Script to ssh and run a command doesn't work

Below is the script. I wanted to login several servers and check for the kernel version. #!/bin/bash #input server names line by line in server.txt cat server.txt | while read line do sshpass -p ...
2
votes
1answer
18 views

ionCube shell script gives error

I have this shell script to install ionCube loader: if [[ $(id -u) -ne 0 ]] ; then echo "Please run as root" ; exit 1 ; fi echo "Welcome to this script to install the ionCube loader on CentOS!" cd ...
5
votes
0answers
113 views

Echo difference between Ubuntu and Red Hat

I have mostly been experimenting with Ubuntu but recently was using a Red Hat Enterprise system and was surprised at a difference I found setting and displaying environment variables. In Ubuntu I ...
5
votes
1answer
22 views

Upstart and bash function names containing “-”

I inherited some bash scripts where the author used "-" in the function names instead of the more normal "_" e.g.: function a-b { ... } Ugly but legal in bash. Problem is I sourced this inside an ...
2
votes
3answers
53 views

Checking if an input number is an integer

I'm trying to check if an input is an integer and I've gone over it a hundred times but don't see the error in this. Alas it does not work, it triggers the if statement for all inputs ...
3
votes
5answers
155 views

efficient cross-os file size shell function

I'm looking for a simpler way to have a cross-os-unix file size check. I could use wc -c but I'm concerned the performance may suck on large files (I'm assuming it just counts chars and doesn't do a ...
1
vote
3answers
116 views

Calling a function which calls another function with a for loop

I am calling a function with a for loop and saving the returned value to a variable. When I run the code, I get a command not found error. What is wrong? #!/bin/bash check_1() { x_$1=$(check_2 ...
0
votes
2answers
37 views

how to pass a value to a variable that in a other variable

I am new to scripting. I am getting a "bad substitution" error while running this code. I want to print the values in h_1, h_2, h_3with a for loop. #/!/bin/bash h_1=12 h_2=13 h_3=14 for ((i=1; ...
3
votes
1answer
163 views

How do I fill my password automatically from .bash_profile when running command as sudo?

I know I could just put something like sudo mypassword in my .bash_profile, but I don't want to run every command as root. I want password to autofill under following circumstances: only the ...
3
votes
1answer
34 views

Error when calling a script from inside another script

I'm writing a couple of scripts to start vlc and periodically update its playlist. The update_pls.sh works well if I execute it from prompt, but when I call it from start_vlc.sh, in each for cycle I ...
-1
votes
0answers
17 views

Become root after login via plink from Windows host

I m trying to connect to a linux server from Windows host via plink. I couldnt figure out how to become root after logon. I have to login with ordinary user first as I can't change config of the ...
4
votes
3answers
63 views

How do I gracefully suspend and resume `cmd1 && cmd2 && cmd3` chain?

From the previous question it seems I failed to understand how && and ^Z interact properly: $ command1 && command2 && command3 Running command1 ... Running command2 ...^Z [1]+ ...
1
vote
2answers
74 views

aliasing a slightly complex script on Linux/bash

Stormvirux provided this nice script in another thread. It puts column headings on the output of an ls -l listing: #!/bin/bash { echo Permissions links Owner Group Size Last_modMonth Last_modTime ...
0
votes
2answers
70 views

change the extension of all files based on user input

I was taking an online assessment and I got the below question. Create a script located at /usr/local/bin/set-file-extensions that will change the extension of all files in the directory ...
4
votes
1answer
35 views

examine the exit code of processes launched in parallel from a script

Say I have the following bash script: #!/usr/bin/env bash process-1& process-2& process-3& I have two questions: how can I check at the end of my script that all processes exited with ...
2
votes
1answer
33 views

Why doesn't PIPESTATUS work on pipelines within a command substitution

Proof below: Bash 4 Prompt> $(echo hello|sed 's/h/m/'|xargs -I{} ls {} 2>/dev/null|sed 's/ /_/') Prompt> for i in ${PIPESTATUS[@]}; do echo $i;done Output> 0 Prompt> echo hello|sed ...
15
votes
5answers
1k views

Is there a way to tell sudo to set my username as owner for the files created instead of root?

If I do a sudo cp /etc/foo.txt ~/foo.txt, the new file is created with root as the owner. Right now, I see no way around this other than using the last two commands (ls to clarify use-case): ...
1
vote
1answer
27 views

Understand `compgen` builtin command

From help compgen: $ help compgen compgen: compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [word] ...
7
votes
2answers
240 views

Is there a shortcut for repeat the second proximate command in bash?

We all know that !! can repeat the last command you do in bash. But sometimes we need to do some operation like $ python test.py $ vim test.py $ python test.py # here is where I need to repeat the ...
0
votes
0answers
11 views

Determin if the currnet terminal has a dark or light theme [duplicate]

I have several (Bash) scripts that uses ASCII color codes. They look good on my dark themed terminal, however on my colleagues light themed terminal the colors I selected don't look that good. Is ...
1
vote
3answers
46 views

How to handle backspace while reading?

How do I handle the backspaces entered, it shows ^? if tried & how read counts the characters, as in 12^?3 already 5 characters were complete(though all of them were not actual input), but after ...
1
vote
1answer
34 views

How could i flip content of a binary file with bash commands

I was wondering if it's possible to do bitwise conversion on a binary file, with bash commands, (in my case bitwise negation).
3
votes
2answers
53 views

Disable bash's cache of executables in the path

On the rare occasions that I notice bash's cache of things that it has found in the path, it's not because it's helpful, it's because it's bloody annoying. An example: ~ dc$ export ...
2
votes
3answers
44 views

bash: dynamic environment control

I have an application which modifies environment variables. The intent is to launch a bash shell with a modified context-specific environment. When my application modifies the environment, and ...
1
vote
1answer
92 views

Reboot when no network connection does not work!

I have a Raspberry Pi that I use as a NAS for my local network. It works fine, but when I turn off the router to which the pi is connected, it permanently loses the connection. To be able to connect ...
1
vote
1answer
73 views

Command-line parameters in bash script not recognised

I use Debian (Raspbian) Wheezy. If this command line works fine: smsd -c sms/out -i 60 -0 -f sms/smsd.log and this alias also works fine: bsmsd='smsd -c sms/out -i 60 -0 -f sms/smsd.log' then ...
4
votes
3answers
49 views

Is it possible to view the list of file names of a zip file which is inside another zip file?

I know I can use unzip -l file.zip to view the file list of a zip file. But a got a zip file inside another zip file. I tried unzip -l file.zip/sub_file.zip, but failed. Is it possible to view the ...
11
votes
3answers
835 views

How to eliminate annoyances when starting a GUI from a terminal?

I prefer to launch GUI applications from a terminal window rather than by using a graphical desktop. A frequent annoyance is that often the developers haven't anticipated this type of use, so the app ...
0
votes
2answers
43 views

How do I validate a settings(ini) file for the values expected using bash?

After I check if the ini file exists where it is expected to be, which I've learned how to do, I would like to check the file for proper formatting. I'd like to validate any number of "site" entries ...
1
vote
2answers
24 views

Remove all files without a keyword in the filename

I have a list of files in the following fashion: > file1.jpg > file1_orig.jpg > file2.jpg > file2_orig.jpg I want to keep all the files with the extension _orig.jpg and discard those ...
4
votes
2answers
37 views

confusing behavior of emacs-style keybindings in bash

Bash offers many useful emacs-style keybindings for simple commandline editing. For example, Ctrl+w deletes ("kills") word left from the cursor. Another keybinding, Alt+d is supposed to be a "mirror" ...
8
votes
3answers
649 views

What is the usage of $& in bash?

I was looking into special parameters in bash. I am curious to know what is $& and how it is different from $_. I see the following output when running the commands but could not locate the ...
4
votes
1answer
113 views

Backspace deletes Bash prompt

I recently modified my Bash prompt via the $PS1 variable so that I could have color. It is in my .bashrc file: PS1="\\[\e[0;32m[\h::\W] >>\e[m " Now if I type something and then have to ...
3
votes
0answers
9 views

syntax highlighting in bash (in terminal) [duplicate]

Is there a way to make bash shell in a terminal use syntax highlighting? There are few related questions on Stack exchange, but with no clear conclusion. What I am looking for is to have bash ...
3
votes
3answers
223 views

Preventing a specific space from being expanded in a variable

In bash how do you avoid a specific space from being expanded in a variable? Lets say I have this JAVA_OPTS="-Xmx1g" JAVA_OPTS="$JAVA_OPTS -XX:OnError='/path/to/a/script.sh %p'" function args() { ...
0
votes
1answer
62 views

Running Python script over multiple directories and multiple files

Here is my command line for python: python script.py -a .faa -n .fna I have a directory containing multiple directories. Out of these multiple directories, there could be 1 or more folders. In ...
1
vote
1answer
35 views

Calling `source` from bash function

I'm trying to source a file whose name is passed from stdin. My plan is to create a function like this: mySource() { # get stdin and pass it as an argument to `source` source $(cat) } to be ...
0
votes
1answer
55 views

Using bash's “source” command return error though it successfully read config file [duplicate]

I want my bash script to read parameters from config file. Here is what inside the script: #!/bin/bash source /home/myscript/conf/config.conf echo "$username" and below is my config.conf: ...
3
votes
3answers
94 views

Script to email all matching files in a directory

Trying to set up a bash script to automate sending data files. Desired end result is to check a specified directory once per week, make a list of all Excel files modified within the last 2 days, and ...
2
votes
2answers
55 views

Why does the while cycle skips and only reads the first line?

$ ls testscript.sh testservers.txt $ cat testservers.txt serverA IMM 10.2.3.4 USERID PASSW0RD serverB IMM 10.2.3.5 USERID PASSW0RD $ $ $ cat testscript.sh #!/bin/bash # test them.. egrep ...
1
vote
1answer
153 views

Why are these values not appending correctly when appended to the pipeline? [duplicate]

I have a bash script (seen here) that I'm using to sort a list of files in subdirectories by filename. This script appends sorted files in hooks/pre-relevant/, then files named hooks/pre-relevant, ...
0
votes
1answer
30 views

typeset -A is giving error in script

I was using associative arrays in my script, hence I used to declare them by the typeset -A <array_name> command, and it worked fine in the bash prompt But when I use it in my script, I get ...