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
0answers
7 views

Split XML file into multiple file

I have xml that have different nodes, i want to split files like this: <unix> <mm> </unix> <osx> <nn> </osx> When i run the script I want it to make one xml ...
3
votes
2answers
17 views

Dash equivalent of self-redirection of script output

In Bash you can redirect all future stdout output of the currently running script. For example with this script, exec > >(logger -t my-awesome-script) echo 1 echo 2 echo 3 This will end up in ...
2
votes
1answer
17 views

Why different behaviour of trapping EXIT vs INT

Running bash 4.3 on Kubuntu Trusty 64 bit. Please see the following two files: trapping-int.sh #! /bin/bash trap "echo Exiting" INT cat </dev/urandom >/dev/null echo Hello trapping-exit.sh ...
0
votes
3answers
19 views

Mute system error message in a script file and display mine

I have created a simple script to move all the files with .sh suffix in the current working directory to a designated directory if there was no such file, the script should output only an error ...
0
votes
1answer
31 views

Convert XML to SQL using the command line

Is there a way to convert XML to SQL INSERT using the command line, here is examples: <something> <somthingelse>lol</somethingelse> </something> would be INSERT INTO ...
2
votes
3answers
78 views

Using grep/awk/sed to sort and combine 2 files

Ok I am running into a problem. I am taking a wifi log that has MAC addresses listed in it. I want to find out what MAC vendors/manufactors for the devices that are connected to my router. I have 2 ...
0
votes
0answers
32 views

Why is a multiline stdout of a command considered as a single line?

I'm experimenting with while read syntax and there is a thing I don't understand. The most basic scenario which reproduces the problem is the following: a bash script a.sh calls another script b.sh ...
4
votes
1answer
21 views

Why does BASH process substitution not work with some commands?

On occasion process substitution will not work as expected. Here is an example: Input: gcc <(echo 'int main(){return 0;}') Output: /dev/fd/63: file not recognized: Illegal seek collect2: ...
0
votes
0answers
16 views

Specify a file with special characters in its name [duplicate]

$ ls -ltr total 8708 -rwxrwx--- 1 root plugdev 8293 Oct 17 02:39 --layout $ rm *ayout rm: unrecognized option '--layout' $ rm "*ayout" rm: cannot remove `*ayout': No such file or directory ...
6
votes
1answer
197 views

Does bash return anything when it runs a command?

I was found the guide to test if there is a bug in Bash. Namely, when x='() { :;}; echo VULNERABLE' bash -c x does not return anything, it is vulnerable. But are there cases like in C that bash ...
0
votes
1answer
22 views

Back-up script via bash — issues with file paths?

I'm trying to run a back-up bash script in via Plesk scheduled tasks on a CentOS GoDaddy Managed Dedicated Server. I'm having a frustrating amount of trouble with this (made worse by the fact that it ...
3
votes
5answers
164 views

How do I use the “if” command for multiple conditions?

How do I do this? if [ -f town-*.swf ] then mkdir towns fi This checks if town-*.swf exists, but I also need it to look for city-*.swf among others, so I need something like this: if [ -f ...
6
votes
1answer
102 views

Exclude one pattern from glob match

I have several files with the same base filename. I'd like to remove all but one foo.org #keep foo.tex #delete foo.fls #delete foo.bib #delete etc If I didn't need to keep one, I know I could use ...
0
votes
0answers
22 views

Are there scenarios where a space is required after a redirection symbol? [duplicate]

I was recently reviewing some old cron tasks and noticed that I had entries ending with >/dev/null 2>&1 instead of > /dev/null 2>&1 (note the space). That got me to thinking - ...
1
vote
0answers
21 views

Resetting Terminal colors on logout

I am using these setting in my .bashrc to make the terminal colors match the ones in the solarized palette echo -en "\e]PB657b83" # S_base00 echo -en "\e]PA586e75" # S_base01 echo -en "\e]P0073642" # ...
3
votes
1answer
66 views

Help me understand this command

I found this bash command that creates a directory tree in your console window. I find it quite useful, but I don't really understand how all of the special charectors work. Could someone help break ...
4
votes
4answers
86 views

Using jq to extract values and format in CSV

I have the below json file: { "data": [ { "displayName": "First Name", "rank": 1, "value": "VALUE" }, { "displayName": "Last Name", "rank": 2, ...
-2
votes
0answers
29 views

why is my delete function not working [on hold]

#!/bin/bash record() { inodeVar=$(ls -i $1 | cut -d " " -f1) mv $1 $1"_"$inodeVar } Restore() { echo $1 >> ~/.restore.info } # Check whether RMCFG is null and creates bin ...
0
votes
0answers
24 views

route -n gives output “route: fscanf”

If I boot my system and no interface has an IP address I get the above output. However if I give an interface an IP, even if I remove it again, this will disappear. Why does this happen? Is it that ...
2
votes
3answers
25 views

Specifiy Unix TimeStamp Range in Parameter

I am launching a mrjob in bash and need to pass in as parameters a range of gz files which have unix time stamps in them as: filename_9127381923.gz. How to do this in the simplest possible way? I can ...
4
votes
1answer
256 views

Why does “cat /tmp/out1 > /tmp/in2 &” appear as “bash” with the “ps” command?

Consider: mkfifo /tmp/out1 mkfifo /tmp/in2 cat /tmp/out1 > /tmp/in2 & When I run ps it appears as bash in the CMD section. Why?
2
votes
1answer
19 views

PHP CLI and Bash - change behaviour of PHP keyword

Our hosting providers have installed 3 versions of PHP onto our linux box and when I SSH into it the command php points to use/bin/php which is version 5.2, the command php-5.4 points to ...
5
votes
1answer
71 views

While command not found and syntax error near unexpected token [on hold]

I am trying to write a shell script that takes a string input from a user, asks for a file name and reports whether that string is present in the file. Below is my current script. #!/bin/bash while ...
3
votes
2answers
35 views

Help with iterating fieldA in CSV file, where fieldB has specified value

I've been trying to setup a script to run on gitbash, to process a CSV file so each record that has a specific value, the last field is changed from empty ("") to a value that iterates from 1 to 16. ...
2
votes
1answer
29 views

Bash script to verify that an rpm is at least at a given version

I need to write a script to verify that an RPM is at least a given version in Linux. QUESTION 1: How can I get the RPM version in a variable $RPM_VERSION, so that it contains the version all the way ...
3
votes
1answer
22 views

How do I stop screen from clobbering my titles?

I am using bash and GNU screen on centos7. I notice that if I ssh to another server, change the title (via ctrl+a+A), and log out of the server that my new title gets overwritten by USER@HOST:~. How ...
0
votes
0answers
76 views

How I can modify a sh command? [on hold]

I need to modify the code for one of the sh commands. For example: Add a one line of code that prints your name when a command is executed by a user on the shell. I want editing of source code for ...
1
vote
1answer
24 views

How to check PIPESTATUS equivalent during PROMPT_COMMAND execution?

I have a custom $PROMPT_COMMAND in bash that logs the last executed command and its return code. I was using $? for the latter happily until I realized that for piped commands this was insufficient. I ...
1
vote
2answers
36 views

Control which process gets cancelled by Ctrl+C

I have a live CD that boots into Linux and runs a small Bash script. The script searches for and runs a second program (which is usually a compiled C++ binary). You're supposed to be able to abort ...
0
votes
4answers
37 views

How to save in a variable the convert from decimal to binary without use an echo

I've been trying to save in a variable the value of the convert of a number from decimal to binary, like this: num1=10 echo "obase=2;$num1" | bc | tee -a register.txt but I don't want to show it ...
1
vote
1answer
38 views

Pipes & redirection binding precedence with disjuncts, conjuncts etc?

I know of the relative binding precedence of operators ‘;’, ‘&’, ‘&&’, or ‘||’ http://www.gnu.org/software/bash/manual/bashref.html#Lists but when pipes come into the picture along with ...
0
votes
1answer
31 views

How can I write a script which updates a text file?

I have made this script #PACKAGES.TXT array2=( `find . -type f -iname *t?z|awk '{print $1}'|cut -d / -f 3` ) funzioneZ() { echo -e " PACKAGE NAME: $i " } array3=( `find . -type f -iname *t?z|awk ...
1
vote
3answers
42 views

How Long do the Contents of the .bash_history File Last?

How can I modify the contents of my bash_history file? What values or variables control how long the history lasts? Are there any other things I can change to provide finer control of my BASH ...
0
votes
2answers
45 views

How can I use netcat (nc) for chat client server model?

enter code hereI am trying to write a daemon using bash. I will enter my partners IP address and the connection will start using nc partner_ip 2015, likewise on the server I will start the connection ...
0
votes
1answer
33 views

Howto adapt this bash construct to a sh valid construct

On converting some bash scripts to a platform where only /bin/sh is available i'm stumble about this bash construct: #!/bin/sh RSTPD=/sbin/rstpd RSTPCTL=/sbin/rstpctl RSTP=0 ...
3
votes
1answer
38 views

Is checking for exit status other than 0 after a `command || return` unreachable?

I am a shell script beginner and found the following patch of code: function some_fun() { #[...] [ -d ${MKAPP_BUILDDIR}/tmp ] || mkdir ${MKAPP_BUILDDIR}/tmp || return 1 if [ $? -ne 0 ]; ...
0
votes
1answer
35 views

Perl/awk/bash: multiply and sum values putting values inline instead original text [on hold]

I have a text like this: ;--------------------------------------- JOURNEY_ARRAY_01 .BYTE <JOURNEY_00 .BYTE <JOURNEY_01 ;--------------------------------------- JOURNEY_ARRAY_03 ...
0
votes
0answers
48 views

Sometimes command with many pipes makes empty output [on hold]

I am wondering what causes this problem and finding the solution (except for temporary file). When I execute certain code CHIMP+testis_uniq_expression.out file with like this, it makes empty output. ...
2
votes
2answers
46 views

An alias for a command to kill stopped jobs

I wanted to add an alias to my .bashrc so that I could kill all stopped jobs with a command like kill_stopped. I am aware that kill `jobs -p` can be used to accomplish this but I'd rather have an ...
1
vote
1answer
22 views

several virtual profiles for the same user

Many times there are several "identities" which one user uses: for work, open-source, academia etc., all require different ssh keys, editor configurations, git configs etc. I was wondering if there ...
1
vote
3answers
87 views

How to sum match numbers

I'm new at scripting, and need some help. Will appreciate your answers. I got this assignment, which is to find the sum of all five-digit numbers (in the range 10000 - 99999) containing exactly two ...
9
votes
4answers
424 views

Regular expression using \\ vs using \

Why does grep e\\.g\\. <<< "this is an e.g. wow" and grep e\.g\. <<< "this is an e.g. wow" do the same thing? If I add a third slash, it also has the same result. BUT, once I ...
0
votes
2answers
57 views

Why does this Shell script fail as cron job [closed]

I have the following in a shell script, when I run this script it works but when I put this as a cron job it does not work(nothing happens!). How come? script #!/bin/bash ...
3
votes
1answer
20 views

Is there a way to flatten a .pdf image from the command line?

In GIMP, I can import a .pdf, and use the GUI to flatten it (if it was made with many layers) by selecting "Flatten Image" in the "Image" dropdown menu. I can then export the .pdf with a new ...
-1
votes
0answers
35 views

Practical usage of pushd, popd, man, less, and cat in bash [closed]

So i am learning more advanced usages of bash/cmdline due to work teaching me some programming and im trying to wrap my head around some of the following bash cmd's and their purposes. I have been ...
1
vote
3answers
65 views

How to align a table of display nicely

I am trying to create a script that act as a ps command with it's own properties that I want to display. Say this is how processes would look like in ps command: sas 24431 1 0 Oct10 ? ...
1
vote
1answer
41 views

Append to PATH-like variable without creating leading colon if unset

I need to append a directory to PKG_CONFIG_PATH. Normally, I would use the standard export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:$(pyenv prefix)/lib/pkgconfig but PKG_CONFIG_PATH has not been ...
8
votes
3answers
275 views

How can a Bash script tell how it was run?

I have a Bash script I was trying to make to help me run a rather complex command with small changes that it would ask me about through echo and read. I have found solutions to force it to run a ...
0
votes
1answer
50 views

reading file using for, while - behavior

Consider the below scenario 2 vms - 192.168.229.131, 192.168.229.132 Both the vms has it's ip as 192.168.229.151 & 192.168.229.152 in it's /etc/hosts file Say there are around 50 vms like i ...
3
votes
1answer
105 views

What are the bash shell length limitations for here-docs?

What are the length limitations for using here-docs as part of bash command lines? I am finding that short here-docs work fine, but when they get longer there is some point or structure after which ...