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

1
vote
2answers
36 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
84 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
107 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
123 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
62 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
477 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
66 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
262 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) ...
0
votes
0answers
37 views

Use inotify to detect what FTP user changes a file for revision history?

I've set up inotify using incron to detect if a file in the web root is changed. I'm using the triggers IN_MODIFY and IN_MOVED_TO and when it triggers, a bash script copies the file to a specific ...
2
votes
2answers
47 views

How to search many files with regular expression and output matches to lines in a new file?

I have 1000's of source files and I would like to find all text that matches a regular expression and then output each match on its own line in a resulting text file. For instance; // a.cs string ...
1
vote
1answer
95 views

Why does bash output data instead of executing, when a script is piped?

I'm running the following script on Ubuntu 14.04: #!/bin/bash apt-get purge -y nginx apt-get install -y nginx date When I run it like cat /tmp/script | bash, apt-get starts installing, then ...
1
vote
0answers
33 views

Cannot change bash shell in Mac OS X

I'm trying to update bash shell on my Mac OS Mavericks. $ brew install bash $ which -a bash /bin/bash /usr/local/bin/bash $ which bash /bin/bash $ chsh -s /usr/local/bin/bash $ which bash /bin/bash ...
2
votes
3answers
69 views

Reading multiple files one line at a time in bash

I know the basic way of reading from a command in bash: cal | while IFS= read -r line ; do echo X${line}X done But what if I want to read one line from several files/commands in a loop? I've ...
0
votes
2answers
55 views

Using AWK to Print Output of Combination of Unspecified Number of Files

My objective is to move into a subdirectory, call it SUB, which has many text files with 5 columns each and always the same number of rows. I want one large 'sum' file that adds all columns from 2-5, ...
2
votes
1answer
29 views

How to merge duplicated history of command on terminal?

Do you have an experience like this? When you try to find a previos used command on terminal by up arrow and you find $ls # 1st time push `up arrow` $ls # 2nd time push `up arrow` ...
0
votes
1answer
46 views

How to capture return code (not exit code)

I have a script that execute some process and return a number based on the job status. This script is triggered on the back background. i.e. ksh -x myscript.sh 20150102 & My question is how ...
0
votes
1answer
79 views

“too many arguments in [ (test) statement”

this is my first "if-else" script on linux. It gives the error [: too many arguments Code: n=0 if [ $n % 2 -eq 0 ] then echo "even number" fi How to correct it.
0
votes
1answer
62 views

regex find replace strings starting or beginning with backslash

I have a compilation album in my music library that has song titles in the form of ARTIST/ TITLE, which is making it really difficult to cp or mv these files because of the slash. So I'd like to ...
1
vote
1answer
33 views

Calling bash getopts from a function fails the 2nd time

I'm trying to parse arguments passed to a bash function using getopts inside that function. It works when the function is called for the first time but fails on all subsequent calls. Here is a simple ...
7
votes
3answers
493 views

What does `. /path/command` do? (Space after dot, absolute path)

From this guide to Bash completion we learn that in order for Bash to perform auto-completion one must perform . /etc/etc/bash_completion.d/foobar (note the space after .) in order for Bash completion ...
3
votes
3answers
43 views

Append and write out variable-named file from list of variables

I would like to create multiple 'wget' shell scripts to download a batch of considerably large (~3GB) files using our HPC cluster. The names of the files are stored in filenames.txt, like so: $cat ...
3
votes
1answer
119 views

What does . ~/.bashrc command do? [duplicate]

I was viewing my .bash_profile file, and I saw this written inside a block of if statement: if [ -f ~/.bashrc ]; then . ~/.bashrc Can someone explain what the second line is actually doing? ...
2
votes
1answer
35 views

Intercept and modify commands in bash scripts

I have some scripts and some commands in the scripts are like this ./executable arg1 arg2 .. argn I want to change the above command to LD_PRELOAD=/some/lib ./executable my_arg1 my_argn arg1 arg2 ...
1
vote
2answers
115 views

How to lock screen for a terminal session?

as we could use xflock4 command to lock the screen (ask for a password to continue) in an X session; I need a similar way to lock the tty1 session. Is there any? (logout is not working when I call in ...
3
votes
2answers
65 views

Execute command after inotifywait established watches

Inside shell script (test.sh) I have inotifywait monitoring recursively some direcotry - "somedir": #!/bin/sh inotifywait -r -m -e close_write "somedir" | while read f; do echo "$f hi"; done When I ...
3
votes
2answers
141 views

Capture in shell variables the arguments after a command (between brackets)

Suppose I have a file that contains, among many other things, \command{arg1,arg2,arg3} (arguments been paths, expressed with /, ., characters and numbers) But that a user can as well call it ...
0
votes
2answers
52 views

ps output / pipeline execution order

I run ps aux | grep somethinghere. The output shows the grep somethinghere as a running process. My question is, shouldn't ps aux finish first, then grep somethinghere run on its output? Maybe there ...
0
votes
1answer
24 views

Resizing Whiptail to full terminal screen

How to make whiptail full terminal screen? "as big as the terminal", like fluid CSS, something like 100%
1
vote
0answers
60 views

Questions about whiptail and bash functions

I'm a bash newbie. Say I have this script #!/bin/bash function cpp-lang { yum install "Development Tools" } function updatesys { yum -y update yum -y upgrade } whiptail ...
0
votes
1answer
16 views

What port uses my backportpackage or bzr?

I am working in a company what uses Ubuntu Precise on the desktops behind a proxy. The Proxy is available in /etc/environment and set as: http_proxy, https_proxy, ftp_proxy, no proxy and their ...
0
votes
1answer
63 views

Bash escaping is confusing me

Lets say that I have a file (executable) called literally 'a\b'. It just echoes some stuff. Now I want to call that and I can do it by inputting user@machine:~/test$ ./a\\b into my console. Now ...
0
votes
1answer
31 views

Redirect all bash script output (from inside the script) to two files: one append, one rewrite; but discard output to the console

I can easily redirect both standard and error output of a bash script to the file, while discarding an output to console with simple exec statement: exec &>>/var/log/backup.log But how do ...
1
vote
1answer
43 views

Whats wrong in creating/printing this array?

To find the average time taken to create certain files, I'm using this minutes array, then would simply use bash arithmetic to find the average. However I'm unable to get the difference except for the ...
0
votes
1answer
85 views

vim - “Press ENTER or type command to continue” right after loading only?

Recently my vim has developed the habit of displaying Press ENTER or type command to continue the first time I do certain things right after I open it. For example, if I'm at my shell prompt and type ...
0
votes
2answers
35 views

process substitution for opening a list of files with an application

I wish to use process substitution to direct a list of files (produced, for example, by ls or find) to a particular application for opening/viewing. While piping such a list to xargs is suitable for a ...
3
votes
1answer
83 views

Unix: Bash Limiting Output to X Amount of Lines

I am trying to modify a script so that it will truncate the output that goes to another file to a maximum (for example: 1000 lines). I have read about split, but what I understand is that split by ...
0
votes
2answers
42 views

Setting up a script on an AMI box to create directories - vsftpd, pam, mysql

I'd like to first say I'm a noob when it comes to linux, so please excuse my confusion. I'm trying to setup vsftpd on a amazon ami 64 bit box, free tier micro. Following these instructions, ...
2
votes
2answers
257 views

How do I use a function return as a condition of an if else then shortcut?

There are instances where a function needs to execute and return to the caller and this works for me. if tst; then echo "success" else echo "failure" fi function tst () { return 0; } ...
1
vote
0answers
19 views

java version not found in redhat

My OS is redhat linux. It's having the default java 1.4.2, but I need java 1.7.45, for that I am trying as follows: /usr/sbin/alternatives --install /usr/bin/java java /u01/java7/bin/java 5 ...
2
votes
3answers
159 views

Loop over associative arrays by substring

In the following code, I create some associative arrays in a loop. The consist of two strings, a string identifier and a year. After creation, I want to access the arrays in a loop based on the ...
0
votes
2answers
36 views

Locate specific file from script

I've written a script file in which, one function searches for another script and if found, executes that script. Script extract #!/bin/bash ... service_status() { local my_script=`which ...
2
votes
1answer
27 views

Strange characters in GIT completion

I'm running bash GNU bash, version 4.3.25(1)-release (x86_64-apple-darwin13.4.0) on OS X 10.10.1. A week or so ago I've noticed that autocompletion has stopped working, but only for git. I'm ...
1
vote
1answer
37 views

Broken git autocompletion after I have overridden the git command

Recently git branch <tab> started showing me the following error: $ git branch bash: -c: line 0: syntax error near unexpected token `(' bash: -c: line 0: `/usr/bin/git --git-dir=.git ...