Questions specific to GNU’s Bourne Again SHell, as opposed to other Bourne/POSIX shells. For questions about Unix shells in general, use the /shell tag instead.

learn more… | top users | synonyms

0
votes
2answers
97 views

Different results invoking bash diretly or via soft link

On my Red Hat Linux system /bin/sh is a link to bash $ ls -l /bin/sh lrwxrwxrwx 1 root root 4 Sep 27 13:17 /bin/sh -> bash Running this contrived test program directly gives me the expected ...
0
votes
3answers
163 views

Extracting index.php?dir=foo/bar/&file=bar2.jpg to foo/bar/bar2.jpg

I have a lot of files with names like: index.php?dir=IOP%2FFOO%2FBAR%2F&file=ScanImage001.jpg After replacing index.php? with nothing %2F with '/', dir= with noting and file= with nothing: ...
4
votes
1answer
3k views

How to use defined function with xargs

This is my code #!/bin/bash showword() { echo $1 } echo This is a sample message | xargs -d' ' -t -n1 -P2 showword So I have a function showword which echoes whatever string you pass as a ...
2
votes
0answers
33 views

git report moved lines

I want to track the number of additions and deletions that exclude moved lines. So if a commit has 10 additions, 5 deletions, and 3 moved lines, then I have 7 additions, 2 deletions excluding moved ...
5
votes
3answers
1k views

source my ~/.bash_aliases from a script not in ~/

I want to update my aliases from a script. I have some new aliases in ~/updateFiles/newAliases: alias ga='git add -A' I also have this update script ~/updateFiles/updater: #!/bin/bash cp ...
3
votes
3answers
2k views

How to copy, execute and retrieve data from a remote computer?

I am trying to run some calculations on a remote computer. Basically I want to copy some files to the computer, load a software, execute the calculation, then retrieve the data back. I have created a ...
19
votes
2answers
2k views

Are the terminal color escape sequences defined anywhere for bash?

I've used every so often colors in Bash scripting (mostly on CentOS), but to make their usage more convinient I end up redefining variables to color values: local GRAY="\[\033[1;30m\]" local ...
7
votes
1answer
9k views

Finding largest file recursively

I am trying to find the largest file in a directory recursively. If there is a subdirectory inside of that directory the function needs to go inside that directory and check to see if the largest file ...
4
votes
1answer
166 views

can we use something better than more for tab completion?

more is not as convenient as less. Is it possible to use something better than more for tab completion, when ls and then tab? Thanks.
4
votes
3answers
3k views

Why when I ssh into one server it shows bash and the other have my username?

So at work I have two web servers that I am able to ssh into. Both are RHEL 6.5 When I log into one, it shows this: [username@ldvweb01 /]$ When I log into the other one it shows: -bash-4.1$ ...
-1
votes
1answer
18k views

convert CSV to XLS file on linux [closed]

The following Perl script can convert CSV file to XLS file the problem is that I need to install on customer Linux machine many Perl modules in order to run this Perl script , and actually I cant ...
0
votes
2answers
361 views

Where can I download i686 RedHat 4 bash package?

https://rhn.redhat.com/errata/RHSA-2014-1293.html The offical announce is only starting at RHEL 5. There are no packages for RHEL4? According to Wikipedia, it's still supported until the start of ...
0
votes
3answers
143 views

How to remove newlines from an ip a s output?

INPUT ("ip a s" command) 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 ...
4
votes
1answer
3k views

How to pass environment variables to a non-interactive shell (with example)?

In a sh script another sh script is started with su -l <user> -c /path/to/script.sh. As far as I understood script.sh will be run in a non-interactive shell. The official documentation tries to ...
1
vote
1answer
2k views

shellshock solution for nexenta/solaris

I'm trying to solve the shellshock issue on my system: SunOS localhost 5.11 NexentaOS_134f i86pc i386 i86pc Solaris # bash --version GNU bash, version 3.2.48(1)-release (i386-pc-solaris2.11) ...
0
votes
1answer
192 views

SSH to a server, execute update command that continues even after logging off the ssh session

Okay I saw a lot of questions like this, but almost all have either theoretical answers which do clear the concept but I am still not able to put it up in code. What I want to achieve using a bash ...
2
votes
2answers
418 views

How to prevent screen from terminating once process ends [duplicate]

I'm launching a process in a named screen like: screen -dmS myscreen bash -c "export VAR=123; cd /usr/local/myproject; ./myscript.py" However, after a few minutes, my script crashes and when it ...
0
votes
1answer
394 views

Redirect a directory as input to a script and output to a file

I want to use a directory name as a parameter for a pre-made script. Then the output goes into a newly made file in the home directory. It involves pipe/redirection. How do I do that? read dir $dir ...
1
vote
3answers
489 views

Input two numbers and add them when “a” is typed, subtract when “s” is typed

So I'm having a little trouble with this code. When i try to execute I get the message line 12: 0: command not found #!/bin/bash let results=0; echo "First number please" read num1 echo ...
11
votes
2answers
682 views

Why is a variable visible in a subshell?

The Learning Bash Book mentions that a subshell will inherit only environment variables and file descriptors, etc., and that it will not inherit variables that are not exported: $ var=15 $ (echo ...
8
votes
1answer
470 views

Why does bash even parse/run stuff put in the environment variable?

The shellshock bug in bash works by way of environment variables. Honestly I was suprised by the fact that there is such a feature like: "passing on of function definitions via env vars" Therefore ...
2
votes
2answers
337 views

Non-printing escape sequence: when?

Recently, I have been playing around a lot with color in the terminal and, therefore, with escape sequences, too. I've read the relevant parts of the Bash manpage along with numerous helpful pages on ...
5
votes
2answers
10k views

echo test | stty -echo -> stty: standard input: Inappropriate ioctl for device

I was playing with a perl script that takes user input with the following: system( qw( stty -echo ) ); $? == 0 or die "Error unable to disable character printing.\n"; print "$prompt: "; my $input = ...
0
votes
1answer
56 views

Using $BASHPID in grep statement

I'm trying to exclude the PID of the subshell from the results returned by pgrep. Note that the name of the file is the same as the name passed to pgrep. Why does setting a variable equal to BASHPID ...
4
votes
2answers
7k views

Bash vulnerability CVE-2014-6271 (Shellshock) fix on Debian 6.0 (Squeeze) [duplicate]

I upgraded my old Debian 6.0 (Squeeze) server, but still the vulnerability seems to be there: $ env x='() { :;}; echo vulnerable' bash -c 'echo hello' vulnerable hello How do I upgrade Bash to ...
6
votes
3answers
3k views

Do I have to reboot after updating bash to avoid shellshock?

I've updated my systems to the latest versions of bash (Fedora: bash-4.2.48-2.fc19.x86_64 and CentOS: bash-4.1.2-15.el6_5.2.x86_64) Is merely updating enough to avoid the exploit or do I need to then ...
10
votes
4answers
10k views

Legacy Debian versions and Bash Shellshock

We are running Debian Etch, Lenny and Squeeze because upgrades have never been done in this shop; we have over 150 systems running various Debian versions. In light of the "shell shock" of this ...
5
votes
4answers
2k views

Is there a difference between read, head -1, and sed 1q?

The following commands seem to be roughly equivalent: read varname varname=$(head -1) varname=$(sed 1q) One difference is that read is a shell builtin while head and sed aren't. Besides that, is ...
8
votes
2answers
191 views

Why is the ability to definine functions in an enviromental variable not a security risk in itself?

As I understand it, generally it is considered safe to let anyone provide information that will be stored in an environmental variable. The shellshock vulnerability is an issue here because it means ...
20
votes
6answers
2k views

Do we have more history for cd?

cd - can move to the last visited directory. Can we visit more history other than the last one?
1
vote
1answer
88 views

www server restart after upgrading bash regarding the shell shock bug?

If a webserver uses CGI with bash, does it calls bash every time when there is a request regarding CGI or does it caches (bash and related libraries) it when starting the webserver? Q: So is a ...
2
votes
4answers
571 views

Bash - How do I loop through subdirectories and extract the files

I have a directory called 10K_TIF (main directory). Within this main directory are multiple sub-directories each containing tif images. I want to read each TIF image and extract its path using a bash ...
5
votes
3answers
1k views

Shellshock: Why this error when testing for vulnerability

I am using Fedora 20 on two machines. Having read about the Shellshock vulnerability, just now at 1100ish UTC on September 26th 2014, in UK, after a yum update bash to protect against it, I tried ...
8
votes
2answers
2k views

How to capture ordered STDOUT/STDERR and add timestamp/prefixes?

I have explored almost all available similar questions, to no avail. Let me describe the problem in detail: I run some unattended scripts and these can produce standard output and standard error ...
2
votes
2answers
199 views

Correct way to find this (shellshock patch) package?

I was out to patch some squeeze servers for the shellshock bug. A few googles later I found that I could updated my apt sources list. This did however not work for some reason. I tried to search for ...
0
votes
1answer
180 views

Bash crashes when running common commands [closed]

Open Bash, run Top, and about 1/3 times, bash just closes. The other 2/3 times, it runs properly. The same thing occurs with other commands like "clear" or "/sbin/ifconfig" Any ideas what may be ...
4
votes
3answers
428 views

How to convert an unsigned decimal (less than 1<<32) to 4 bytes (binary) in bash?

Example: $ decimal=$(( RANDOM << 17 | RANDOM << 2 | RANDOM >> 13 )) $ echo $decimal $ printf "%08x" $decimal | xxd -r -p >bytes The result is in bytes file. Can it be done in ...
3
votes
2answers
2k views

Interacting with a running interactive console program from a different process

I have a console program with an interactive shell, similar to say, the Python interactive shell. Is there an easy way to start this interactive program A and then use another program B to run A? I ...
1
vote
3answers
644 views

Modify some files to add the file name

I have a bunch of text (hundreds of txt) inside a directory. Each of them has a unique filename. I want to insert filename of each file into the first line of respective files. How can I do that using ...
2
votes
2answers
559 views

Interactive multiple choice in a bash script

Is there a simple way to let the user interactively choose one of the lines of the output of lsblk -f? NAME FSTYPE LABEL MOUNTPOINT sda ├─sda1 ntfs WINRE_DRV ...
0
votes
0answers
26 views

Can't set PATH with a script [duplicate]

I have written a script which was supposed to add some value to environmental variable PATH, but script doesn't do that if I start it with ./script.sh. #! /bin/bash INSTALLDIR="/opt/ARM" ...
1
vote
3answers
178 views

Bash Combine Replacement and Sub String Extraction in One Step

For a string in this format: ./my-site.sub.domain.com I would like to remove the .,-, and /, and trim the remainder to 16 characters: mysitesubdomainc I've done this ...
1
vote
1answer
90 views

help organizing ssh aliases

My .ssh/config is starting to grow with aliases, and remembering them all is getting harder. Do you have any tips for better manage this growing collection? For example an autocomplete when I type ...
3
votes
1answer
2k views

/bin/sh: error importing function definition for `some-function'

I encountered this error when updating bash for the CVE-2014-6271 security issue: # yum update bash Running transaction (shutdown inhibited) Updating : bash-4.2.47-4.fc20.x86_64 /bin/sh: error ...
2
votes
0answers
2k views

How to test shellshock against remote machine using a simple script [closed]

I am interested in testing for shellshock vulnerable machines that I don't have shell access to on my LAN's and WAN's such as IPMI cards and Internet of things devices. What is the best way to ...
4
votes
2answers
706 views

Parenthesis works in bash shell itself, but not in bash script

As the title says, I can run this command from my command line prompt: cp -r folder/!(exclude-me) ./ To recursively copy all contents of folder except for the subdirectory named exclude-me into the ...
1
vote
0answers
169 views

Maintain screen session when executing shell script on boot

Solved: I solved this problem by introducing a delay before executing the script: @reboot sleep 60; /root/start_server.sh On Ubuntu 14.04, I have a crontab entry set to run on reboot: @reboot ...
1
vote
0answers
160 views

Ubuntu 14.04 HDMI UDev Script

I have tried multiple variations to this script but I cannot get it to work. The UDEV Rule fires the script and the script exectutes but simply does not change the audio profile. If I run the script ...
4
votes
6answers
127 views

How can I cd from parent1/suba/subb to parent2/suba/subb without listing subdirectories?

I have multiple parent directories with the same file structure beneath them. Example: parent1/suba/subb/ parent2/suba/subb/ When I am in parent1/suba/subb, I would like to change to ...
1
vote
2answers
215 views

How does the latest “Bash Bug” or exploit affect systems that require authentication?

I'm curious to know how the latest Bash Bug affects systems that require a user login to access the shell. Isn't UNIX/Linux usually configured in a way that you have to be an authenticated user to ...