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

centos gdrive script, upload to new folder

I'm using https://github.com/prasmussen/gdrive Hello, I'm trying to run a daily script that creates a folder in google drive and then uploads a bunch of tar archives in it. So far I can create the ...
0
votes
1answer
31 views

Is it possible to put an if statement within an If statements like so?

As my title suggest I'm trying to put an if statement within an if statement. It seems to work until the last echo command in the script which doesn't print. For testing I have created a directory ...
1
vote
1answer
31 views

escaping filename results from grep

How do I escape the output of grep so that bash can read the file names correctly? I have a text file that is the output of a find command. For each line, I want to make a symlink. For now, I'm just ...
1
vote
2answers
49 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
25 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 ./**/...
0
votes
2answers
18 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 ...
1
vote
1answer
50 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 ...
0
votes
2answers
74 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 ...
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 ...
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/...
2
votes
2answers
36 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
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 ...
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: ...
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
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 ...
-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.
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 ...
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
3answers
59 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 ...
3
votes
5answers
195 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 ...
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 ...
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 ...
1
vote
1answer
35 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 ...
3
votes
2answers
137 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: ...
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 ...
3
votes
2answers
82 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 ...
7
votes
1answer
137 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=...
0
votes
1answer
26 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 ...
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 ...
-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 ]; ...
0
votes
2answers
33 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 ...
0
votes
1answer
47 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" ...
0
votes
2answers
27 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
63 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 ...
-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]) ...
1
vote
2answers
53 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 $...
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 ...
0
votes
0answers
45 views

command works from line but not from bash [closed]

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
26 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 [[ $...
2
votes
2answers
89 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 ...
1
vote
1answer
41 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 ...
-3
votes
1answer
40 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
1answer
59 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 ...
3
votes
1answer
48 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 (...
1
vote
2answers
41 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 [$?] \$ ' #...
4
votes
2answers
213 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
vote
2answers
42 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 ...
0
votes
1answer
64 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" == "...
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, ...