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

2
votes
0answers
36 views

Why is bash -c cutting off the end of my script? [duplicate]

I have a simple script, that is essentially a list of dpkg -i ... commands in a chroot. It looks something like this: chroot /path/to/chroot /bin/bash -e << EOF cd /opt dpkg -i package1_* ...
2
votes
2answers
58 views

Custom bash 'context' when running from FISH

First of all, I'm on OSX10. My default shell is BASH, which I have set up (through .profile and .bashrc) to automatically run the FISH shell when I open my terminal emulator. This allows me to set up ...
1
vote
0answers
31 views

Autocomplete issue in bash with equal sign (=)

I am trying to make autocomplete work and wroted a piece of code to demonstrate an issue I faced up: $ cat completion.sh function _completion_command() { compopt +o bashdefault +o default +o ...
0
votes
3answers
92 views

create XML file using bash script

I want create simple xml file using bash script ( not with dom ) but when I set value in the line then echo print the $lorem word and not the val lorem=LOL echo '<root><foo ...
0
votes
1answer
45 views

Exit /dev/tty after error message

I run this bash function when a button is pressed, it calls my mobile, however when the call ends or I reject the call, it hangs in /dev/tty and does not return to the main program call.sh ...
1
vote
3answers
268 views

How can I pass on parameters 4..99 to another function

I'm calling a function and I want to pass up to 100 paramters onto another function. I do not want to pass on the first 3 params, I start with param4 being the first param for the other program. I ...
1
vote
0answers
37 views

Limit transfer speed rate by Iptables Rules

I have D-Link Router DSL-2730U that support busybox OS and iptables version 1.4.0 I managed successfully to block the host for being connect to the internet using the following command block by ip ...
1
vote
1answer
29 views

Can .bash_profile be auto sourced after change?

I'm always wondering if there's a way to do this. I don't want to type source after changing my .bash_profile all the time.
1
vote
1answer
101 views

grep (/sed/awk) month range

I've looked around for solutions to this, but it's sort of difficult to search for the solution to such a specific problem (lot of words to put in Google). So, I have a file with data that looks like ...
-1
votes
1answer
36 views

Script to `grep` a file with variable [duplicate]

while read wholeline do echo ${wholeline} --outputs John Jones #grab all the lines that begin with these values #grep '^John Jones' workfile2 --works, prints contents of workfile2 where the ...
2
votes
2answers
97 views

How do I have sed only perform actions on the first match?

I have a bash script that extracts headers from the MIME Source of an email. The idea is that I only want to capture the headers of the message nothing else. It's not quite working right though. I ...
0
votes
2answers
35 views

script for substition incremental

I have 4 machines, every machine(centos) has a ifcfg-bond1 with identical ip address 10.0.0.3 How to using bash and sed substituting 10.0.0.3 with a incremental value? I want to obtain something like ...
0
votes
0answers
39 views

Bash - Convert escape character colored text to BBCode

I want to convert a terminal escape-character colored text file to BBCode colored text. For this i've created an Android logfile with logcat -Cd > /sdcard/logcat.txt. The -C switch adds the color ...
0
votes
2answers
42 views

Different PATH formats for .bash_profile [duplicate]

There are few different formats I have seen so far: With quotes and brackets: PATH="/usr/local/bin:${PATH}" With quotes only: PATH="/usr/local/bin:$PATH" None: PATH=/usr/local/bin:$PATH ...
2
votes
1answer
204 views

How to create permanent aliases on Unix-like systems?

I am looking for a simple way to create a permanent alias for all users. So ~/.bashrc or ~/.bash_profile is not an option. Hasn't anybody created a program for this? I think it should be a very ...
1
vote
1answer
37 views

Ctrl-Arrow does not work anymore after installing Prezto

I have this in my .inputrc: "\e[A": history-search-backward "\e[B": history-search-forward set show-all-if-ambiguous on set completion-ignore-case on # mappings for Ctrl-left-arrow and ...
8
votes
4answers
386 views

How can measure how long it takes my script to run AND include that in an email it generates?

I have a simple bash script that runs a series of checks (ping, nslookup, etc) and then sends an email report with the output of that data. I'd like the email to include information on how long it ...
1
vote
2answers
92 views

How to handle spaces in path names when variable contains multiple paths [duplicate]

Although I've read myself through most of the questions about handling spaces in path names, I haven't found my case yet, which is about several path names in one variable. find will need this when ...
1
vote
3answers
107 views

sed won't expand my BASH variable in script

I have this script, which will prompt for the relative or absolute path to the file and then swap whitespaces ' ' with '\ ' which works in Linux console. Substitution is done using the first sed ...
5
votes
3answers
97 views

Split an input for different command and combine the result

I know how to combine the result of different command paste -t',' <(commanda) <(commandb) I know pipe same input to different command cat myfile | tee >(commanda) >(commandb) Now ...
4
votes
3answers
79 views

Bash, insert last used argument of current command

I'm aware that you can recall the last argument of the previous command with !$ and also cycle through previous arguments with ALT + . but can you recall the last argument used for the current command ...
1
vote
5answers
72 views

Comparing float values in bash

My if expression always evaluates to TRUE somehow. ROTATION variable is 0.000 or 90.000, a float value or it seems so ROTATION="$(mediainfo --Inform="Video;%Rotation%" $VIDEO$ORIGINALEXTENTION)" echo ...
1
vote
1answer
42 views

File that is only readable with root privileges

I have a binary file that needs to run at startup on all accounts (including unprivileged user accounts), so a command to run it will be put into /etc/rc.local. The program itself will have only ...
3
votes
2answers
178 views

Is there any way to determine the signal that was caught from inside a bash trap function?

I have a bash script, in which I have specified via trap that a function will be called for any (catchable) signal. typeset -i sig=1 while (( sig < 65 )); do trap myfunc $sig let sig=sig+1 ...
0
votes
0answers
118 views

Using chown $USER:$USER inside bash script

In a small bash script I'm running I am attempting to chown a new directory that is created. I've added: sudo chown $USER:$USER /var/www/$sitename sudo chmod 775 /var/www/$sitename after the line ...
3
votes
4answers
97 views

How to sum time using bash?

I want to know the total amount of time that a series of processes would take in my computer to decide if I should running there or in a stronger computer. So, i am forecasting the running time of ...
1
vote
0answers
25 views

What types of regex DO support (e.g.) negative lookbehind?

Bash on GNU: I am using a collection of find commands, most of which employ -regex to do their matching. Each time I try a different feature in my regex I have to cycle through the values for ...
0
votes
1answer
16 views

php shell_exec() + /dev/hwrng: no output

I have this PHP script: <?php $od = shell_exec('od /dev/hwrng --address-radix=n --read-bytes=4 --format=u4'); ?> <html> <head> <title>hwrng</title> </head> ...
12
votes
1answer
230 views

How can I loop over possible completions? [duplicate]

I'd like to be able to get my hands on an array of possible completions for a given partial command. For example, the partial command service um has the following possible completions: $ service ...
0
votes
2answers
34 views

how to use bash to run a same command with a group of variables?

I want to run all those commands within some better arrangement, what should I do? # bash script of "copyall.sh" scp /local/michael.txt root@example.com:~/ scp /local/jason.txt root@example.com:~/ ...
10
votes
3answers
787 views

What does `1>>` and `2>>` mean in a bash script?

I have the following bash script, from what I understand >> is used to append the output of a command to an existing file instead of overwrite, but what is it doing in this case? This script is ...
0
votes
2answers
71 views

sed to replace a word from a file with the contents of another file? [duplicate]

I have two files file1 & file2. Contents of file1: Text1 Text2 Text3 Contents of file2: Sample1 Sample2 Sample3 I would like to replace the word Text1 from file1 with the contents of ...
0
votes
1answer
27 views

Running a “scheduled”/delayed script as sudo on server, via ssh - and right before ssh exit

This would have probably been answered by Keep running a script via ssh, if I didn't have to run a command as superuser. Let me try with an example: say on my server, I have this script as ...
1
vote
3answers
120 views

Shell script to delete multiple files

So, I have a file which contains a list of hundreds of files that need to be deleted from various directories. I figured the easiest method would be to create a batch file but I'm not having great ...
0
votes
2answers
26 views

Keep execution of bash script when aborted via CTRL+X or CTRL+C

This is very nooby question I belive and I've tried everything to avoid asking it here, but I didn't found answere anywhere on whole internet. Go on and give me downvote but please answer me how to ...
1
vote
2answers
35 views

Why quotes are retained in string variables when surrounded by single quotes?

I needed to retain the double quotes around a string variable defined in bash in order to be able to pass it to a dialect of the Scheme programming language. My question is why are the double quotes ...
0
votes
2answers
83 views

arch linux systemd RTC clock script does not execute

I have rtc.service service in /etc/systemd/system: [Unit] Description=RTC Service [Install] WantedBy=multi-user.target [Service] Type=oneshot RemainAfterExit=yes ExecStart=/scripts/script_rtc.sh ...
0
votes
0answers
17 views

How to capture the consolidate the output of files into one file, and append any new information?

Currently I have this to grab the output of many individual files and consolidate them into a single logfile. However is it possible when I run this in the future to only append new data, instead of ...
1
vote
3answers
53 views

Shell script to find and count total number of characters in all the files

How can I make a script that finds every file in your home directory that is less than 3 days old and then gets a count of the total number of characters in all of these files?
1
vote
1answer
50 views

How to add the content of a text file to the middle of another text file

I tried to use sed, but I realized that it doesn't allow to charge a complete file. I am looking for a quick and neat way to: a.txt a b c b.txt d e f And obtain c.txt a d e f b c
2
votes
1answer
106 views

Why can't I kill this process?

Problem I would like to kill a process called raspivid (program which records videos using a Raspberry Pi Camera) but I cannot... This is how I call it: #!/bin/bash #Start recording... raspivid -w ...
3
votes
2answers
120 views

Copy files in same folder and replace year in its name

How can I copy a lot of files in the same directory replacing the year in its name? I have this (can be different filename and extensions): filename1-2014.ext filename2-2014.ext filename3-2014.ext ...
0
votes
0answers
26 views

Bash script results in errors like “: command not found”. Using Sublime Text to edit the file in Windows [duplicate]

I had a ~/.bash_profile which I wanted to move to somewhere where it'll be executed for all users, including the root. I was led to /etc/profile which worked great. I appended my script there and it ...
0
votes
2answers
59 views

Use .sh or .bash extension for bash scripts?

(See Use #!/bin/sh or #!/bin/bash for Ubuntu-OSX compatibility and ease of use & POSIX) If I want my scripts to use the bash shell, does using the .bash extension actually invoke bash or does it ...
9
votes
4answers
473 views

Use #!/bin/sh or #!/bin/bash for Ubuntu-OSX compatibility and ease of use & POSIX

I know that I can use either as the first line of scripts to invoke the desired shell. Would #!/bin/sh be recommended if compatibility with all unix systems is an absolute requirement? In my case ...
4
votes
1answer
64 views

Deleting input forward to the next space

When in terminal I can use Ctrl+w to delete a whole word or IP (. is separator for each octet) when going leftward of prompt. However, if I try Alt+d to go rightward of prompt, terminal recognizes "." ...
0
votes
1answer
23 views

Can I treat all what I typed after a command as raw string?

I made a bash func for myself so I can through some words into a tree_hole file, it looks like this in bashrc: function th { echo -e "\n$@" >> /Users/zen1/zen/pythonstudy/tree_hole; } export -f ...
1
vote
0answers
29 views

In bash instead of creating new line changing the already made line [duplicate]

Ok hard to explain in few words so I was wondering how instead of creating a new line......like lets say I want to: while true; do echo "hello"; sleep 1; done then I want it to count the number of ...
7
votes
2answers
261 views

How do redirection in a symbols work in a sequence?

I have file1, file2, file3. file1 contains 1 file2 contains 2 file3 contains 3 I use command cat file1 > file2 > file3 Results in: file1 1 file2 (contains nothing) file3 1 Why ...
3
votes
1answer
54 views

Filename expansion from date ranges

Consider dates in the ISO 8601 format i.e. ‘YYYY-MM-DD’, e.g. 2015-01-28, and say we have a folder with files of the form: AAAA_<date>_BBBB I am looking for a glob pattern in zsh (or Bash) ...