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

0
votes
1answer
39 views

inputrc not loading correctly

I added the following to my ~/.inputrc: set show-all-if-ambiguous on # single tab to start completion help set completion-ignore-case on # completion is case-insensitive $include /etc/inputrc ...
2
votes
4answers
74 views

Change text in tag, but only tag is contained within a certain XML block

Using Git Bash, I'm trying to conditionally replace what's in the yrot tag in hundreds of files, but only if it belongs with a part name tag that pertains to wheel. // YES, change <part ...
23
votes
2answers
2k views

What does a dollar sign followed by a square bracket mean in bash?

It appears that $[expr] performs arithmetic expansion just like $((expr)). But I can't find any mention of $[ in the bash manual. This command gives no results: gunzip -c ...
3
votes
2answers
323 views

“echo $IFS” does not return the value of IFS

I have set the IFS to x, i.e IFS=x. Now if I check the value of IFS, then it appears to be empty if I do not use double-quotes: ~ $ echo $IFS | cat -e $ ~ $ echo "$IFS" | cat -e x$ ~ $ echo $HOME ...
0
votes
2answers
22 views

“Syntax error:unexpected end of file ” upon bash script execution [closed]

Running Fedora 21 on my VM. I am receiving "Syntax error:unexpected end of file " upon bash script execution. There is no line 35 in my script. why am I getting the error?
4
votes
1answer
38 views

can't run remote ssh command without heredoc

I can't get this command to work: user@server:~: ssh otherserver bash -ic 'source .profile; some-aliased-command' Variations I tried user@server:~: ssh -t otherserver bash -ic 'source .profile; ...
5
votes
2answers
325 views

Read multiple lines from text files in bash

When I am shell scripting, the majority of what I am doing is wrapping the I/O of other modules in python, matlab, etc. To do so, I usually use text files or something of that nature with the ...
1
vote
1answer
47 views

How to activate Virtualenv when a Python script starts?

I want to schedule a python script to run using cron on certain dates, the problem is that in order for example.py to work, example-env has to be activated, is there a way to make example.py activate ...
8
votes
1answer
72 views

OS X, bash: less works on open file descriptors, cat doesn't

In a bash script I'm working on (which has to run on Ubuntu and OS X), I need to redirect the output of hundreds of commands to a file. Rather than appending &>... to all of them, I simply do ...
0
votes
2answers
39 views

How do I add Metasploit into my PATH variable?

I have Metasploit installed on my Mac in /usr/local/share/msf. Everytime I want to use it I have to cd into that directory and use msfconsole. If I try to /usr/local/share/msf/msfconsole in my home ...
2
votes
2answers
77 views

How do you add a bash script to your PATH variable using symlinks?

I run a gaming server called PocketMine. So basically I have a folder in my home directory that has a bash script to run the server: ~/PocketMine/start.sh Everytime I want to run the server I either ...
3
votes
1answer
63 views

Regex for crontab validation

I need to check in bash whether an entry into the crontab file is valid. Is there a crontab command switch? I can extract individual lines and try to control individual items through regex. But I ...
1
vote
0answers
40 views

Bash CGI script won't run [closed]

I have made a webpage to control the GPIO pins of my raspberry pi to control a rc car. I use cgi scripts written in bash. I can let the car drive forwards with this script: #!/bin/bash gpio -g write ...
3
votes
1answer
41 views

bash silently does function return on (re-)declare of global associative read-only array

Obviously cut out of a much more complex script that was more meaningful: #!/bin/bash function InitializeConfig(){ declare -r -g -A SHCFG_INIT=( [a]=b ) declare -r -g -A SHCFG_INIT=( [c]=d ) ...
1
vote
2answers
76 views

Bash - incremental history search (ctrl+r) - matching multiple non-adjacent words

When using Ctrl+R to search bash history, is there some way to match two words that aren't next to each other. For example, let's say I wanted to find the last command that contained httpd and awk ...
0
votes
2answers
44 views

Adding a new directory to PATH vs. a symlink for directory already in PATH

In setting it up so I could execute Sublime Text from bash, I discovered two methods of doing this via different tutorials: Method 1) Create a symlink from /usr/local/bin/subl to Sublime's bin dir: ...
0
votes
0answers
32 views

Create the button's action with glade

I used linux glade to create interfaces of a bash script but I can not configure the button's actions the first interface asks the user to choose the type of the query. When they click the button ...
0
votes
4answers
71 views

Unix bash/ksh : Selection of first non space character from file from specific line

I have file file1.txt whose contents are as follows: Date List ----------- Quarter Date Year Date Month Date Now I want to read the non space elements from each row of ...
11
votes
3answers
128 views

Understand “IFS= read -r line”?

I obviously understand that one can add value to internal field separator variable. For example: $ IFS=blah $ echo "$IFS" blah $ I also understand that read -r line will save data from stdin to ...
2
votes
3answers
31 views

Truncating the precision of a date

I'm working with a bash script which polls build progress from several different systems. If a build is complete, it stats a log file to find out the last time it was edited, then feeds that time into ...
1
vote
1answer
28 views

running command before shtudown doesn't seem to work

I've created an ubuntu server kiosk based on some guide that I've found and I'm trying to stop the kiosk before the shutdown. The kiosk is being started automatically or manually with the command sudo ...
1
vote
2answers
44 views

How to remove all files in a directory except hidden ones?

I'm cleaning an output directory before I put things in it. I want to track the output directory in git with a .gitkeep file, but this keeps on getting deleted with my rm -rf "$OUT_DIR" line in a ...
0
votes
2answers
43 views

expect: does “” (spawn_id exp70) match glob pattern

I have written an expect script that works perfect for testing passwords on our network until it has looped through my list quite a bit, then the debug output shows that there is nothing to match. ...
2
votes
3answers
83 views

Format column-based text file into tree structure using bash

Is there a Unix/Linux command that can turn this: AMERICA USA NEW_YORK AB-100 AMERICA USA NEW_YORK VF-200 AMERICA USA NEW_YORK XY-243 AMERICA USA LOS_ANGELES UH-198 AMERICA CANADA TORONTO ...
1
vote
1answer
44 views

Running a program and providing input

I have a program that runs from the command line. As soon as it runs, it asks for a text value and expects the return key to be pressed after that. Is that possible to create a bash script that runs ...
2
votes
5answers
260 views

Bash script: check if a file is a text file [closed]

I am writing a menu based bash script, one of the menu options is to send an email with a text file attachment. I am having trouble with checking if my file is a text file. Here is what I have: ...
0
votes
1answer
43 views

Delete duplicate entries in a text file [duplicate]

I created a txt file using two requests, one LDAP and one SQL. Results of the two requests are stored in the same txt file. The txt file looks like this : user1@domain.fr user2@domain.fr ...
1
vote
1answer
48 views

why grep does not print the entire line? [duplicate]

When I enter ls command I get the below output. -$ ls aNode ANode bNode BNode cNode CNode DUMP file1 hello.txt TEST.txt -$ As seen, above output is one line which has filenames separeted ...
1
vote
2answers
43 views

add ordering number to specific text

Is there any way to add a number into a specific text? On my text file: <a href="http://localhost/file1.txt">file </a> <a href="http://localhost/file2.txt">file </a> <a ...
2
votes
2answers
54 views

How do i run a command only after previous command is unsuccessful in bash? [duplicate]

We use && operator to run a command after previous one finishes. update-system-configuration && restart-service but how do I run a command only if previous command is unsuccessful ? ...
0
votes
1answer
69 views

predetermine script input text

I have a script that automatically sets up an emailing server based off what I enter for the following echo "Please enter your main domain: (Ex.: website.com)" read DOMINIO if [ $DOMINIO = "" ]; then ...
1
vote
2answers
65 views

Pipe ssh's output (stderr and stdout) to different commands

I'm a writing script for some kind of backup involving ssh and rsync. Every time that script runs I redirect all output to a log file. To standardize the log-entries I wrote a log-function that adds a ...
2
votes
1answer
35 views

How to set pipe of process after process substitution in bash so that process continues after script ends?

How can I set up a process that has had its output redirected via process substitution so that it can survive after the parent script exits? I am trying to set up a Bash script to monitor the output ...
1
vote
1answer
36 views

Why does this bash fork bomb not work on my RHEL VM?

I'm running a RHEL 6.5 VM in a VMware ESXi environment and accessing it through the vSphere Web Client virtual console (in my browser). I wanted to crash this machine on purpose and executed :(){ ...
0
votes
1answer
52 views

How to catch first line of stdout from bash process substitution?

I am working with the following block of bash and it is not printing out the first line of expected output: exec 3< <(python3 -m http.server) while true; do read -t 2 line ...
2
votes
7answers
172 views

Restart firewall from bash file

I need to restart firewall periodically, so I created a bash file to add it to CRON tables. In terminal, I restart firewall using command: service firewall restart but if I have similar line in ...
1
vote
3answers
34 views

Execute a database query by iterating through results of a previous query

I'm new to Unix and bash scripts so please bare with me if this is a silly question. I've just started working for a company that uses DB2 hosted on a Unix platform and there are a lot of unwanted ...
28
votes
6answers
3k views

Is 'cat' a shell built-in or an external program?

When I use the type command to find out if cat is a shell built-in or an external program I get the output below: -$ type cat cat is hashed (/bin/cat) -$ Does this mean that cat is an external ...
1
vote
4answers
59 views

Remove all brackets in filename

I've been trying to remove all brackets in my filename(s). Can anyone help me create a bash script to do that? This bash script below work flawlessly for non-bracket filename(s), but if there are any ...
2
votes
1answer
26 views

repeat bash history expansion substitution for all the matches

:& repeats bash history expansion substitution. For example: $ echo 1 1 1 1 1 1 1 1 1 1 $ ^1^9 echo 9 1 1 1 1 9 1 1 1 1 $ echo 1 1 1 1 1 1 1 1 1 1 $ ^1^9^:& echo 9 9 1 1 1 9 9 1 1 1 $ echo 1 ...
0
votes
3answers
58 views

backup script to copy files by its extension

I have created script to copy .png files from one directory to another. Script is as follows: i="`cat /usr/local/app1/default.conf | grep -i values | sed -e 's/\values=//g' -e 's/,/ /g'`" for data ...
1
vote
2answers
45 views

Find file which name contains given substrings simultaneously

In general, it's often needed to find a file whose name should contain several substrings simultaneously. How do I do that with bash? For example, "boost", "qt" and "linux" in a file called "How to ...
2
votes
3answers
194 views

Using sed command to find the first occurrence of the pattern and append

Say there is a text file as below: Hello world types="" Mario types="Game" All I want to do is find the first occurrence of type="" and append with word program My desired output: Hello world ...
5
votes
1answer
50 views

How do I make a custom “command not found” prompt for the terminal?

I want to make a custom "command not found" prompt for the terminal like this one. I have the template set up: ___________________________________________ / I see you're trying to use the ...
2
votes
3answers
47 views

Pasting some text with tabs into a here-document in a PuTTY window

I have a string with tab delimited data that looks like: h1 h2 a1 b1 a2 b2 I produced it with Notepad on Windows. I created tab delimited data, ensuring that tabs and not spaces are used. I ...
3
votes
2answers
52 views

Simultaneously check for empty output and successful exit status

I'd like to write the following test in an installer script1: if [ -n "`/etc/grub.d/30_os-prober`" ]; then install_dual_boot else install_linux_only fi However, it's also possible that ...
0
votes
1answer
43 views

How to create a bash script that sees all files in a directory and tells me their size and date of creation?

I'm a beginner in the field of programing/coding. I'm trying to write a simple bash script that will see all files in a directory, and then tell me each file's size and each of their dates of ...
1
vote
1answer
45 views

Nested quotes in subshells

Say I have to use quotes to encapsulate subshell output like: DATA="$(cat file.hex | xxd -r)" But I need to nest this kind of stuff like: DATA="$(cat file.hex | xxd -r | tr -d \"$(cat ...
2
votes
2answers
47 views

Trying to transplant bash to /mnt for chroot, what does bash want in order to work?

I have a stage 3 gentoo tarball.. extracted it to /mnt which is hosting /dev/sda3. Though there was no bin and no sign of bash after unpacking. Far as I'm aware, the rest of the configuration involves ...
0
votes
1answer
57 views

How can I set a bash_logout for all users?

I've run into an issue trying to set up a little bit of ASCII art to display upon connection and on logout. I can do this for one user with .bashrc and with .bash_logout, and set a login MOTD by ...