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

7
votes
3answers
25k views

How do I clear the terminal History?

I am using Linux Mint 17.1 Rebecca for about 2 days and accidentally typed my password into the terminal which is now displayed in the history list of commands I have previously typed. I want to ...
16
votes
2answers
42k views

sudo: unable to execute ./script.sh: no such file or directory

I'm stumped. I have a script in my /home directory which is executable: [user@server ~]$ ll total 4 -rwx------ 1 user user 2608 Jul 15 18:23 qa.sh However, when I attempt to run it with sudo it ...
0
votes
2answers
38 views

How can you pass parameters to function in a script?

I'd like to write a function that I can call from a script with many different variables. For some reasons I'm having a lot of trouble doing this. Examples I've read always just use a global variable ...
2
votes
2answers
20 views

Resize image in a script using Imagemagick

I'd like to create a bash script to resize images up to 800px keeping proportion... My code doesn't work in bash, but it works using identify with a single image : #!/bin/bash for file in ./**/...
1
vote
1answer
38 views

Func name as variable in loop

Overview: I save my variable in a config file and call them later. Each entry with the name FailOverVM has a number beside it like FailOverVM1 and I want to check to see if it has data and generate a ...
42
votes
5answers
20k views

How to run a program in a clean environment in bash?

I want to run a program in an empty environment (i.e. with no envariables set). How to do this in bash?
0
votes
2answers
16 views

How to define an alias without executing dollar signs contained inside?

I have the alias : alias gwanip=echo "$(dig +short myip.opendns.com @resolver1.opendns.com). This works fine except I just realized that it executes the command dig everytime bashrc is sourced. How do ...
-3
votes
1answer
38 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 ...
0
votes
3answers
2k views

VLC script on ubuntu server

I need a small script which run three vlc command on the same time (on Ubuntu server 14.04) as stated below: #!/bin/sh cvlc -vvv v1 --sout "#transcode{vcodec=h264,vb=999,acodec=mp3,ab=128,...
1
vote
4answers
41 views

Create an associative array from the output of two commands

I am trying to create user directories based on an imported passwd file, and am trying to load the data into an associative array: array[username]=directory . I can load the fields into a separate ...
2
votes
3answers
42 views

Extract files with specific file extension and keep directory structure?

I have a lot of .CR2 and .ARW files mixed together in a directory structured by date (2016 has the folder 06 and 07 within it with a folder for each day in them. So a file could be located in 2016/06/...
1
vote
1answer
43 views

Escaping bash variables before storing them in an apache hive database

I'm running a script file sqoop_import_ATM.sh and would like to store the logs in a SQL database. First thing I did was to direct the logs into my own variable: OUTPUT="$(/home/me/...
0
votes
2answers
70 views

Split file by pattern

Is there an easy way to split, for example, apache vhost file with multiple vhost into 1 vhost per file? Or something else, allowing to operate only one by one vhost to get grep output . preferred ...
-6
votes
3answers
71 views

Bash script won't run

I'm trying to run a bash script named serverloadtest.sh to test a server is performing correctly. However, when I type serverloadtest.sh all I get is 'command not found'. I'm definitely typing the ...
2
votes
2answers
35 views

Default assignment to a null variable with command substitution

I'm trying to use the syntax: A=${B:-C} where A is the variable, B is the value I'm trying to assign, C is the default value if B is null. Now I want to replace B with the command nc -l 443, so if ...
5
votes
2answers
66 views

Is getopts always available for Bash?

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

Unset http_proxy enviroment variable

Updated 11/03: After doing some test with your suggestions, I only can be sure about one thing: there is something related to the graphical environment, because if I login through ssh or using a ...
5
votes
5answers
338 views

Defining the start and end point of a loop in bash

I have a directory with folders sequentially numbered 1-1000, however I want to perform an action for some of the folders in this directory. i.e folders 1-50. How do I define the start and end point ...
2
votes
1answer
28 views

Bash script to re-run program when it finishes or crashes

This is what I have so far: until python MyApp.py; do echo "App crashed... restarting..." >&2 sleep 1 done This will re-run the program when it crashes, but not when the program finishes ...
5
votes
3answers
257 views

How to check if a glob has an expansion? [duplicate]

Is there a good clean conventional way to do this? For example, if there are any ".gz" files in a certain directory, I want to unzip them. But if there aren't, I don't want to see any error. If I ...
24
votes
4answers
15k views

how to download a file using just bash and nothing else (no curl, wget, perl, etc.)

I have a minimal headless *nix which does not have any command line utilities for downloading files (e.g. no curl, wget, etc). I only have bash. How can I download a file? Ideally, I would like a ...
0
votes
1answer
25 views

Trying to convert a list with multiple meanings

I am trying to convert a list into another using a conversion list, but the conversion list has multiple meanings and I am unsure how to approach this. For example I have this list with only numbers: ...
3
votes
5answers
194 views

Comparing multiple options in a bash (string)

I'm trying to enable only certain options when using the read command, and to exit the script if a wrong possibility was entered. Tried many possibilities (array, variables, syntax change), but I'm ...
1
vote
2answers
42 views

cleaner script to recursively replace a string in all directories and file names [duplicate]

I want to replace a string with a different string in all directory and file names, recursively. So if I want to replace foo with bar and have this file: foo_project/my_app/old_foo/start_foo.sh I ...
1
vote
1answer
34 views

compress all pdf files recursively

i want to compress all my pdf files in an given directory and its sub-directories using ghostscript. I´m stuck using the find command within loops by filename including spaces. Here some example ...
1
vote
3answers
108 views

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

After some very quick research, it seems Bash is a Turing-complete language. I wonder, why is Bash used almost exclusively to write relatively simple scripts? Since a Bash shell comes with Linux, you ...
21
votes
3answers
37k views

How do I check if a file is a symbolic link to a directory?

I can check, if a file exists and is a symbolic link with -L for file in *; do if [[ -L "$file" ]]; then echo "$file is a symlink"; else echo "$file is not a symlink"; fi done and if it is a ...
-3
votes
0answers
23 views

How do I make a 2 column table out of a text fle list? [on hold]

I have a rolo (addresses) text file that I would like to make into a 2 column text file. Thanks, Hearthstone.
17
votes
4answers
14k views

Autocomplete server names for SSH and SCP

I have a few servers configured in ~/.ssh/config, such as alpha and beta. How might I configure Bash such that the commands ssh al<tab> and scp file.tgz al<tab> autocomplete the names of ...
2
votes
3answers
58 views

Bash script : ls command not found

Under Arch USB iso, zsh, running the script ./test containing : #!/bin/bash PATH=$(dirname $0) ls $PATH returns ls: command not found Any idea how to fix this ? EDIT : ls alone works but ...
0
votes
0answers
35 views

init=/bin/bash times out after minute?

I'm trying to debug an ARM based device running a form of embedded Linux (arch) by setting grub to mount: rw init=/bin/bash It boots into a root shell as expected, but after about a minute, the ...
0
votes
1answer
791 views

-bash: command: command not found [closed]

I'm trying to run a program from the command line, and I got a -bash: command: command not found error. What can I do to troubleshoot/fix the problem?
3
votes
2answers
40 views

How to output into clipboard and paste in bash tty?

How would I put the ls output inside the bash tty clipboard and then how would I paste it in the command prompt ? Alternatively how do I put the output of a command in the command prompt directly so I ...
3
votes
2answers
81 views

Remove all files, except for two

I would like to delete everything in one folder, with the exception of two files: exec.js .git I found this: rm !(exec.js|.git) Which works in the CL, but when I try to store in a sh file, and ...
3
votes
2answers
134 views

executing alias on variable in bash

I am a bash newbie and I came upon this strange behaviour in my bash script. #!/bin/bash V=a alias $V="echo test" echo $(a) #returns 'test' echo $($V) #returns ...'a: ...
7
votes
1answer
136 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=...
21
votes
4answers
35k views

Why doesn't my ~/.bash_profile work?

I'm using Linux Mint. My login shell (cat /etc/passwd | grep myUserName) is bash. After I start my graphical desktop environment and run terminal emulator from it, I could see that .bash_profile is ...
0
votes
1answer
50 views

problem in login with default /bin/fish shell in gdm

I set fish as default shell for my user in Linux. /etc/passwd file: mlibre:x:1000:1000::/home/mlibre:/bin/fish and now, in GDM I can't login with my user (mlibre). GDM prints some error. I turned ...
1
vote
0answers
58 views

Does RPM automatically retry failed download attempts?

My particular situation isn't on a Linux box, rather an IBM i. But I'm running RPM within a BASH shell and attempted to download and install nano using RPM - it failed. I didn't think anything of it,...
0
votes
3answers
50 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 ...
4
votes
3answers
873 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
36 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 ...
-1
votes
1answer
35 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
25 views

Functions in ~/.bash_profile not found in an interactive shell [duplicate]

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
32 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
30 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
1k 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
31k 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?