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
3answers
35 views

How to automatically append a command to a file when called in a shell?

I'd like to keep track of all the programs I'm installing, so every time a command contains pacman -S (important space after -S) I'd like bash to append the command string to a file. Currently I'm ...
2
votes
3answers
80 views

How complex can a program be written in pure bash? [on hold]

So after a very quick research, it seems bash/shell (whatever it is called) is a Turing-complete language : https://en.wikibooks.org/wiki/Bash_Shell_Scripting#What_is_Bash.3F I wonder, why is the ...
4
votes
3answers
866 views

Unicode text doesn't appear correctly in shell

I'm using the terminal in Kali Linux and I try to type Arabic text the characters are shown but separated (appearance not correct) This what my shell shows me ex. لا ا ل ه ا لا ا ل ل ه, which should ...
3
votes
1answer
2k views

bash: non blocking read inside a loop

I have a following small bash script var=a while true : do echo $var sleep 0.5 read -n 1 -s var done It just prints the character entered by the user and waits for the next input. ...
0
votes
1answer
31 views

how do you make a list/file for pacman to install from

I am trying to move from one arch install a (partitioned one) to another (a less-partitioned one) on my computer and I want a similar set up. So I was wondering if there was a simple way to get pacman ...
7
votes
1answer
114 views

How to extract the string between two \n in a file

I have a file with pattern <span class="WebRupee">Rs.</span>\n29\n<br/><font style="font-size:smaller;font-weight:normal">\n3 days\n</font></td>, <td class=...
-1
votes
1answer
34 views

Adding Function to array based on index [on hold]

I am using Bash. I am trying to add a function to an array. I tried using: if [ $CONTROL -eq 0 ]; then array[$index]+=`function_name1` fi if [ $CONTROL -ge 1 ] && [ $CONTROL -le 20 ]; ...
4
votes
4answers
2k views

How to count occurrences of all the words in all the files of a directory using grep? But with count incremented only once per word per file

I have already asked a similar question but people misunderstood what i was asking. I was asking how to generate a list of every word with a word count incremented only once per word per file. For ...
0
votes
1answer
20 views

Functions in ~/.bash_profile not found in an interactive shell

I thought that whatever lies in .bash_profile(or .profile) which is sourced in a login-shell, is available in an interactive shell. My goal is to have available a list of functions, either in a login ...
0
votes
2answers
28 views

Preform operation in bash only if a variable is less than a second variable

I am building an OS for a virtual machine I made, and while progress has been coming along swimmingly, I have been stuck for a good several hours on what should be a very simple issue: I am designing ...
1
vote
1answer
29 views

How do certain commands change the tabbed autocomplete criteria?

Suppose I am in a directory like this: :mydirectory$ ls foo.txt That only file. If I type a command like cat and then I tab to autocomplete (assume the ‸ character is actually the caret ...
3
votes
2answers
985 views

Cannot rm file: Disk quota exceeded

In bash (and over ssh) running rm FILENAME gives the error: rm: cannot remove 'FILENAME': Disk quota exceeded. I've seen the other posts (and everyting down the first page of google) on this topic and ...
20
votes
6answers
30k views

In linux, how to delete all files EXCEPT the pattern *.txt?

I know how to delete all txt file under current directory by rm *.txt. Does anyone know how to delete all files in current directory EXCEPT txt file?
2
votes
2answers
578 views

How to control buffering of pipes in bash scripts?

I need my script to be executed with stdbuf -i0 -o0 -e0 otherwise user will wonder why there is no output (becuase of pipe buffer). How can I acheive it? #!/usr/bin/stdbuf -i0 -o0 -e0 /bin/bash ...
1
vote
1answer
40 views

Can Bash process substitution be used as part of argument expansion?

I'm familiar with process substitution used the canonical way, e.g. diff <(ls /folder1) <(ls /folder2) However, can it be used when the process asks for an argument that is not just the path ...
0
votes
2answers
202 views

How to pass variable into parallel script from text file line by line

I need to read a file line by line and pass the string as a variable for a script to be run in parallel. ex: 14 43 57 is in foo.txt if I var=$(cat foo.txt) then I can use this $var for inside a ...
1
vote
2answers
38 views

Condition Inside String in Bashscript

I want to print exit code of previous command in shell if it failed. So I changed PS1 variable in /etc/bash.bashrc like this: PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w [$?] \$ ' #...
2
votes
1answer
231 views

change terminal appearance according to server

I have 2 different serves (all running Linux) to which I connect via ssh . After login all terminal background looks same. I want to have different color theme or background for different servers. For ...
0
votes
1answer
38 views

If-else Statement or command inside a function?

It's possible to have a if-else inside a function? Like here that I have a menu. Please see codes below. #!/bin/bash #Main Menu function p_enter { echo "" echo -n "Press Enter to continue" ...
8
votes
3answers
3k views

How to tell if terminal session is running within screen

When running a bash script, I would like to be able to tell if it is running within a screen. Is this possible? I want this so that .bashrc can set the colour of the command prompt depending on ...
0
votes
2answers
2k views

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

I am trying to write a daemon using bash. I will enter my partner's IP address and the connection will start using nc partner_ip 2015, likewise on the server I will start the connection using nc -l -p ...
2
votes
5answers
399 views

Generating QR code of very big file?

I want to generate a QR code of my 4096-bit armored GPG private key. The key is so big, the program qrencode seems to fail because of its size. $ gpg --export-secret-keys --armor > ~/private.key $ ...
1
vote
2answers
51 views

How redirect stderr to variable inside if condition? Bash

I try get standard error communicate from mkdir -p $FINAL_BACKUP_DIR and send in message by logger. It make log more complete for example the user will be know he do not have permission or $...
4
votes
2answers
207 views

Replace the first occurence of a pattern in a file that may contain a slash

Thanks to http://stackoverflow.com/questions/27787536/how-to-pass-a-variable-containing-slashes-to-sed I know how to pass a variable that contains slashes as a pattern to sed : sed "s~$var~replace~g"...
-1
votes
3answers
33 views

Error when answering a confirmation in bash

I am making a simple confirmation prompt, here is the code read -r -p "Are You Sure? [Y/n] " input case $input in [yY][eE][sS]|[yY]) echo "Yes" ;; [nN][oO]|[nN]) ...
0
votes
2answers
24 views

Removing space at the beginning of the variable data

I would like to ask if how can I remove the space in the beginning of the stored data of the variable. I had an auto-generated script that will get MySQL COUNT from the DB. MYSQL COUNT SCRIPT-> .ini ...
1
vote
1answer
60 views

$($string) execution failure

I have $(${StrVar}), my StrVar has $ in value eg. test$9hp. When I execute the command: $(${StrVar} it fails as $9 is inside my variable and it tries to expand it. function Deploy { # in this ...
28
votes
7answers
4k views

Why does [A-Z] match lowercase letters in bash?

In all shells I am aware of, rm [A-Z]* removes all files that start with an uppercase letter, but with bash this removes all files that start with a letter. As this problem exists on Linux and ...
1
vote
2answers
978 views

Find last line of a file for matching string?

I want a loop that runs infinitely over a file but always checks the last line to see if it contains the matching string if it does then echo that line and keep the loop running. What I have right now ...
0
votes
1answer
273 views

Argument list too long with just 5000 files [duplicate]

I have a folder with 5000 files that I want to copy somewhere else. When I do cp ../folder* ., I get the following error: -bash: /bin/cp: Argument list too long However, getconf ARG_MAX returns ...
-3
votes
0answers
24 views

How to Do Error-trapping and Swapoff if Error/Warning?

Pseudocode where incomplete pseudo try-catch after cas' comment #!/usr/bin/env bash # http://askubuntu.com/q/799834/25388 # Use: `sh myScript`; sudo does not work with Matlab. #set -e # no ...
1
vote
1answer
19 views

How to create a “Configuration Information [Automatically generated, do not change]”?

I was reading a thread on the bug-bash mailing list and saw: Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu ... Since this "Configuration ...
2
votes
2answers
83 views

Exclude from wildcard (*) using find

I have a command in bashscript that will find the files from a wildcard folder name and count it from that wildcard folder we have a test folder that I want to exclude from count. Here is my command ...
0
votes
0answers
44 views

command works from line but not from bash [on hold]

When I run ffmpeg -ss 0 -t 0 -i "$inputfile" -c:v libvpx -crf 10 -b:v $bitrate -vf scale=-2:-2 -an "$outputfile" from my terminal it works fine if I replace the variables with actual values. When ...
1
vote
1answer
24 views

Bash Built-in Regular Expression Usage

I've tried to find all line's which begin with at least 1 tab. Several Variations didn't work out. The most Basic one: #!/bin/bash FILE=emptiness { while IFS=""; read line do regex='^[\t]+' if [[ $...
0
votes
1answer
58 views

Sourcing a file multiple times in a bash script

I have a large configuration script (bash) that is pretty well modularized into separate functions to complete a bunch of tasks for installing/configuring a new rollout of a software suite. We have ...
1
vote
2answers
40 views

Redirect tty to standard

I have a script which outputs things on /dev/tty, so it cannot be outputed into logs or anything by default. I would like to capture ALL outputs of the given script from another script to store it to ...
16
votes
5answers
14k views

Check if pipe is empty and run a command on the data if it isn't

I have piped a line in bash script and want to check if the pipe has data, before feeding it to a program. Searching I found about test -t 0 but it doesn't work here. Always returns false. So how to ...
3
votes
1answer
45 views

Using bash variable with escape character in awk to extract lines from file

I am writing a bash script (just learning bash) to extract some lines from a file based on two patterns. The first pattern is just a sentence ending in a colon. The second pattern is a * repeated N (...
3
votes
1answer
38 views

Shell that tab-completes prefix?

I would like tab completion to behave differently when the cursor is at the beginning of a word than when the cursor is at the end of a word. I've only ever seen shells that tab-complete the suffix, ...
17
votes
4answers
2k views

What's the difference between eval and exec?

eval and exec are both builtin commands of Bash (1) that execute commands. I also see exec has a few options, but that is the only difference?
-3
votes
2answers
167 views

Find the number of files with sizes

Find the number of files with sizes > 100KB in /, /bin, /usr, /usr/bin and /usr/sbin directories and output them in a two column format with the name of the directory and the number of files.
-10
votes
2answers
221 views

replace the the first line of all .sh files in a folder

Create list of all .sh files in current folder. Check first line of each file in this list and if file starts with #!/bin/sh then replace that with #!/bin/bash. Only modify files that have #!/bin/sh, ...
5
votes
2answers
62 views

Is getopts always be available for Bash?

Can I use getopts for parsing command-line arguments in my bash scripts(not sh) without worrying about another depedency?
29
votes
4answers
25k views

What is the meaning of IFS=$'\n' in bash scripting?

At the beginning of a bash shell script is the following line: IFS=$'\n' What is the meaning behind this collection of symbols?
3
votes
3answers
109 views

How to read a properties file into an associative array?

I'd like to read the properties in a properties file into an associative array. How can I do it? Specifics on what to parse: hash and equal signs. Everything else is a bonus. Properties file content ...
-4
votes
1answer
49 views

What can single quote mean specially within double quotes? [on hold]

From bash manual Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes, with the exception of ‘$’, ‘‘’, ‘\’, and, when history expansion ...
0
votes
1answer
58 views

Read Input From Command Line

Trying to use the "read command" to accept user input from the command prompt itself but my script doesnt seem to be moving forward echo "Do you want to continue?(yes/no)" read -p $1 if [ "$1" == "...
6
votes
1answer
521 views

What is a *.sorted command and why doesn't it work in my bash?

In a Bash Guide for Beginners (sec. 3.2.1.2. Local variables) there is an example command which is supposed to list all of the local variables, that are not in enviromental variables, or so I think: ...
4
votes
0answers
36 views

Mixed languages in bash after OS X update to El Capitan

In my user, which has admin privileges, I have several languages enabled, and English (U.S.) is the 'Primary' language: After updating to El Capitan (10.11), I get mixed languages in bash: $ svn ...