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

26
votes
1answer
1k views

Why can Shell builtins not be run with capital letters but other commands can?

Why is this? When I do this CD ~/Desktop It doesn't take me to the Desktop. But this: echo "foo bar" | GREP bar gives me: bar
1
vote
1answer
27 views

Fastest way to find whether a file exists in a number of tarballs? [closed]

Is there a more efficient way to do this other than using tar tf and checking the output of every file against the file that I'm looking for? This is the way I do it right now, but it's very slow ...
2
votes
1answer
65 views

why completion does not work for all aliases?

In my .bash_aliases file I have couple of aliases, like -- shopt -s expand_aliases alias emx='emacs' alias em='emacs -nw' alias gv='gvim' alias v='vi' alias ev='evince' when I use them and press ...
2
votes
0answers
73 views

Write the same file multiple times to one file using dd

I am trying to create large dummy files on a drive using dd. I am currently doing this: #!/bin/bash writeFile(){ #$1 - destination directory/filename, $2 - source filepath $3 - blocksize, $4 - ...
4
votes
4answers
344 views

How do I remove every number that's surrounded by <>

I have tried this sed -i '' 's/[0-9]*<>/g' But it didn't work. Example file: <Number1> </Number8> output: <Number> </Number>
4
votes
2answers
355 views

How do I populate end tags using sed, awk or any other command?

I have a txt file that looks like this: <sss>ss< or <firstword>anotherword< I want it to look like this <sss>ss</sss> or ...
1
vote
1answer
68 views

How to grep the logs for a list of patterns and make a report out of it?

I have a C++ executable which scan some of my files and those files has some user id in it. After scanning is completed it generates below log file (abc.log) like this - INFO [0x7faff2b32a00] ...
3
votes
1answer
63 views

Echo out lines of script before running them

Is there a way to run scripts in bash that makes it so that it prints each line of the script before executing it? This would be really useful to me for debugging... $./myscript.sh echo "Hello" ...
0
votes
2answers
71 views

Running Tasks in Parallel using Bash

I am using this script to analyse data. #!/bin/bash inlist=/aut/cl/tera/mja/scripts in=/aut/cl/tera/mja/data/ran_ready/ out=/aut/cl/tera/mja/data/mas/aft/ for i in $(cat $inlist/list.txt); do echo ...
0
votes
3answers
63 views

Pipe/redirect a group of commands

I currently use the following setup to redirect the output of multiple commands: echo "Some normal commands" ( echo "Error: something happened" echo "Warning: this incident will be logged" ) >> ...
0
votes
1answer
28 views

Getting video card product name in terminal

My laptop is equipped with an Intel i5-3317U CPU that, according to this, comes with an Intel® HD Graphics 4000 video card. However, with lspci | grep VGA I get "Intel Corporation 3rd Gen Core ...
-5
votes
1answer
90 views

Extract multiple lines from text file [closed]

Source : ! hostname RTR-1 ! boot-start-marker boot-end-marker ! logging buffered 64000 informational no logging console ! interface FastEthernet0/0 description LAN ip address 172.16.29.250 ...
1
vote
1answer
46 views

I am try to interactively add a user via “useradd”

I am basically trying to write a simple script to allow for interactive use of "useradd" with select options. The options I am trying to allow for specific use are to either be defined interactively ...
27
votes
2answers
2k views

How does `cat <> file` work?

cat < file prints the contents of file to stdout. cat > file reads stdin until Ctrl+D is detected and the input text is written to file. cat <> file, at least in my version of Bash, ...
0
votes
1answer
41 views

Spaces in directory name Bash [duplicate]

I'm new to bash and I'm working on script that traverses the tar.gz file archive and in each file changes a string specified to an another string. Args of script: name of archive, searched string, ...
6
votes
2answers
193 views

Piping bash string manipulation

I've read some other piping bash string manipulation questions but they seem to be specialized applications. Essentially, is there a way to do the below simpler? instead of $ string='hello world'; ...
1
vote
1answer
62 views

How to fix corrupted bash-completion in command substitution?

it seems my bash-completion got corrupted. Every time I try to use command substitution, for example when I type ls $(ls Deskto<Tab> ..result is.. ls $(ls Desktobash unexpected eof while ...
2
votes
3answers
119 views

Write to stderr

I'm using stderred to color all output streamed to stderr red. It's working fine. But when I write my own bash script and throw an error with echo 'error' 1>&2, it doesn't color the output in ...
0
votes
2answers
107 views

Split XML file into multiple files

I have an xml file 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 ...
5
votes
1answer
65 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 ...
1
vote
4answers
69 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 ...
2
votes
3answers
165 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
46 views

Why is a here-string command substitution 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 ...
5
votes
1answer
57 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
220 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
74 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 ...
4
votes
5answers
221 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
129 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
24 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 - ...
3
votes
1answer
104 views

What is the purpose of those special characters in the sed 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 characters work. Could someone help break ...
-1
votes
1answer
84 views

How to insert the entry into the newline?

I have the following entry in a tab delimited file test1.txt key1 10|15 20 30 11|xx 21 31 key2 527|240 269 0 0 0 2462 546 281 0 0 Is there any way I can transform this file into the below format? I ...
5
votes
4answers
174 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, ...
0
votes
0answers
26 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
26 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 ...
5
votes
1answer
269 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
28 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
147 views

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

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
41 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
36 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
26 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 ...
2
votes
2answers
58 views

Is there a way to execute commands while getting user input?

I’m fairly new to scripting and I have a high-level question of how to do something. I want to design a simple game similar to space invaders, with these two main features for now: Bullets drop ...
1
vote
1answer
31 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 ...
0
votes
2answers
15 views

RPM command stuck/FREEZE when installing RPM file

I want to install the following rpm from some reason RPM is stuck or freeze and not install the RPM package also I cant stop it by control C , please advice what could be the problem ? root]# rpm ...
3
votes
3answers
60 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
47 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
52 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
35 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
56 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
90 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 ...