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
4answers
63 views

grep all strings that start with a certain char, and finish with another char

I need to grep all strings that start with "[" and finish with a certain string, e.g. "apal". So all chars in between these 2 chars would be shown as well. Given an input such as: ...
0
votes
2answers
60 views

How to copy files from directory meeting certain criteria

I'm trying to copy files from directory A to directory B. But I want to copy only files that have lower size then X and don't have file extensions specified in file extension.txt. My main problem ...
1
vote
1answer
30 views

Synchronous processes in the background

I want to launch 2 processes in the background, but I need the 2nd one to wait for the 1st to finish. Both are going to be very lengthy, so I also need to be able to log out from the terminal. At the ...
5
votes
5answers
509 views

Is it possible to run ls or find and pipe it through stat?

Is there a way to run ls or find to get the list of files within a directory and then run stat to get all of the specific information (i.e. File Group, File Name, File Owner, File Size (displayed in ...
0
votes
0answers
19 views

What does @ indicate in long file format? [duplicate]

NOTE: Don't know if this matters, but I'm running commands on OS X Terminal. What does the @ indicate about a file when it is listed in long format, ala: -rw-r--r--@ 1 <user> <group> ...
3
votes
1answer
46 views

Why does nullglob affect tab completion?

After shopt -s nullglob, I noticed that tab completion completely stopped working. Why would that be? extglob is apparently benign, what else could nullglob affect? Observed on: Ubuntu 14.04 (bash ...
3
votes
1answer
121 views

Is it dangerous to always have extglob on?

If I turn extglob on to do things like shopt -s extglob rm !(*.html|*.txt) # remove everything except html and txt files Is it unwise to keep extglob on after this? Are there any caveats of having ...
3
votes
1answer
25 views

Can't export environment variables on X session start

My setup is: Debian testing (stretch), up to date LightDM with autologin enabled Awesome window manager bash, in ROXTerm or XTerm I don't seem to be able to set own environment variables and get ...
3
votes
1answer
58 views

What kinds of commands can run with exec?

What kinds of commands can run with exec? For example, executable files, builtin commands, shell script, compound commands (e.g. looping, conditional branching), pipeline, command list, commands ...
0
votes
3answers
68 views

How to tell if a command executed by `exec` runs successfully or not?

When running a command with exec, the parent shell will exit upon the command finishes running. How can I tell if a command executed by exec runs successfully or not?
3
votes
4answers
133 views

Check if a shell variable has more than one line using built-ins?

I can do this by calling the external utility sed (for a known non-empty $myvar) like so: if [ "$(printf %s "$myvar" | sed -n '$=')" -eq 1 ]; then echo "Your variable has only one line, proceeding" ...
-1
votes
2answers
40 views

How to convert a string into a date in a given format

Need a string in '9-2-1832' format in a '1832-09-02' format. Must be able to fill a 'date' type field in mysql.
0
votes
0answers
13 views

Declaring multiple arrays from contents in multiple directories, then iterating over those arrays and their contents [duplicate]

In a bash script, I'm trying to declare 15 separate arrays with the contents of a folder for 15 separate folders (IE; array1 = contents of folder1, array2 = contents of folder 2, ..., array15 = ...
0
votes
1answer
41 views

“export VAR=thing && someCommand” reports “export: `&&': not a valid identifier”

I'm trying to set an environment variable and execute a command in a single line, like this: export PUB_CACHE=/app/src/.pub-cache && dart-sdk/bin/dart server.dart (Don't ask why... it's ...
-1
votes
0answers
24 views

.bashrc - Create an alias for SSH declare Function [duplicate]

So, I have a function: function () { command1; command2; } When I do ssh root@server "$(declare -f function) function parameter" It works fine. So, I want to make it simplier - through an ...
1
vote
2answers
45 views

Shell eating `?` characters

This is such a simple question that I'm sure it's been asked somewhere, but I can't find it. My shell, which I have not intentionally set up to do so, seems to eat any words involving question marks: ...
1
vote
2answers
55 views

Bash script to get all mp3 file from a html page

I was thinking in a way to get .mp3 files from a html page, manually i did get using wget wget http://www.podcastfrancaisfacile.com/wp-content/uploads/files/question-prix.mp3 So, i try this for an ...
1
vote
2answers
31 views

What would 'passwd root --stdin' have set my password to?

I ran: sshpass -p 'OldPassword' ssh -o StrictHostKeyChecking=no root@1.1.1.1 'echo "Te3EQeF2U!-Em_C3eBU6A&a=u2$e28*c" | passwd root --stdin' Without realizing that echo ...
1
vote
0answers
40 views

Bash scripts not found. Maybe EOL issue? [closed]

I am facing a problem that is driving me crazy. In the past months I have been developing a project based on a Linux distribution (Openwrt) that has been recently updated. My project has a lot of bash ...
5
votes
2answers
277 views

Sed with inplace editing changes group ownership of file

I have shell (php) script that gets in touch with target file this way: inspects whether file and directory are writable with php 's is_writable() (I don't think that this is problem) does in-place ...
9
votes
2answers
809 views

Why does “man” command disappear?

I find man command disappears on my RHEL7: # man ls bash: man: command not found... # which man /usr/bin/which: no man in ...
2
votes
1answer
60 views

Create a file of fixed size with specific contents

I want to create a file of fixed size (1G, 10G, 100G etc) with a single random word of length within the specified limit on every line. I basically want this to run a benchmark which will sort the ...
3
votes
5answers
105 views

Bash while loop read from colon-delimited list of paths using IFS

I am trying to write a bash function that behaves similarly to the where builtin in tcsh. In tcsh, where lists all the builtins, aliases, and the absolute paths to executables on the PATH with a given ...
-1
votes
0answers
26 views

Can you give an example for asynchronous command similar to this one for command substitution?

From Bash Manual Command substitution, commands grouped with parentheses, and asynchronous com mands are invoked in a subshell environment that is a duplicate of the shell environment, except ...
0
votes
0answers
31 views

Why do konsole expand $VAR inside single quotes in <-e> command line option?

I want to print a string and be sure all $VARs inside it are not expanded to their values. That's why I enclose my text in single quotes. Example: echo '$SHELL';read -sn 1 This command displays ...
0
votes
1answer
25 views

Arguments and positional parameters in `bash -c <some-command>` [duplicate]

Bash Manual says about bash -c <some-command>: Read and execute commands from the first non-option argument after processing the options, then exit. Any remaining arguments are assigned to ...
-1
votes
1answer
40 views

What does `bash date` mean? [duplicate]

$ bash date /bin/date: /bin/date: cannot execute binary file $ bash -c date Thu Apr 14 19:27:08 EDT 2016 What does the error message of bash date mean? What does bash expect date to be?
2
votes
4answers
114 views

What is the difference between running a command directly and with `bash -c`?

For a command (builtin or external), what is the difference of running it directly in a bash shell process and with bash -c in the bash shell? What are their advantages and disadvantages ...
0
votes
1answer
22 views

assign string components into variables [duplicate]

Looking for a smarter way to do something I'm doing already. I have a string: "firstbit.secondbit.thirdbit.fourthbit.fifthbit.sixthbit" The content between the periods changes, but the delimited ...
1
vote
2answers
43 views

Why when I try to execute a program as normal user I get denied, and when I execute it with sudo I get “Not Found”

In order to execute mysqlbackup I have to execute it as root. Here's the example when I execute it as normal user: mysqlbackup --compress --user=root --socket=/var/lib/mysql/mysql.sock ...
1
vote
2answers
58 views

bash - All possible combinations of words from different files

I have n files with one word per line file 1 file 2 file 3 ... 1_a 2_a 3_a 1_b 2_b 3_b 1_c 3_c I want to write a bash script that takes all this files ...
1
vote
1answer
27 views

bash set -o errexit problem or the way of incrementing variable?

I have a shell script incrementing a variable like in the example below with set -e: $ var=0; echo $? 0 $ ((var++)); echo $? 1 $ ((var++)); echo $? 0 $ ((var++)); echo $? 0 $ echo $var; echo $? 3 0 $ ...
9
votes
3answers
605 views

Piping a command through a color filter

Does something like this exist in Unix? $ echo "this should show in red" | red $ echo "this should show in green" | green $ echo "this should show in blue" | blue Here I don't mean for literal ...
-1
votes
1answer
35 views

openSUSE frozen on login screen, refuses to return to GUI [closed]

I just came back to my recently installed (overnight last night, just started using it today) openSUSE installation to find it frozen on the lock screen. After various attempts to get it to unfreeze I ...
0
votes
1answer
18 views

bash - npm not found, though installed

ph@vm:~$ uname -a Linux vm 4.2.0-16-generic #19-Ubuntu SMP Thu Oct 8 15:35:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux ph@vm:~$ which npm /home/ph/.nvm/versions/node/v4.0.0/bin/npm ph@vm:~$ npm -v ...
0
votes
2answers
46 views

Get the latest value of an environment variable is a bash shell script

I wonder how can we get the latest value of an environment variable in a bash shell script. Problem I am having is, I have a environment variable which can be changed externally multiple times. But ...
1
vote
5answers
76 views

How to go to each directory and execute a command on specific file?

How do I write a bash script that goes through each directory inside a parent_directory and executes a command on specific file. The directory structure is as follows: Parent_dir/ dir1/ acc.bam ...
0
votes
0answers
18 views

How to make cron job which suspends computer before specified time of the day

I am trying to make script which suspends computer if it is used before specified time of the day or if it is used too long. #! /bin/bash ...
0
votes
0answers
20 views

Automated port change

I want to Create a Bash file that a user can execute to change the port a service runs on. Essentially all I have to do is replace a number in a line of text with another number generated by a list. ...
0
votes
1answer
11 views

Filter for remote server response from netcat SMTP scan

I am using netcat to test if remote exchange server (lets call it exchange1) is online with this code. nc -w 3 192.168.130.17 25 I want to create a file that has that servers name if and only if ...
1
vote
1answer
25 views

Problem saving standard output to variable

Looked some for an answer, but not finding anything that sticks out as a solution. I'm trying to make a bash script, and in it I need to save the output of git rev-parse --show-toplevel to a ...
0
votes
2answers
26 views

Reconstructing a tab-separated record in bash not working

I need to parse a tab-separated CSV file using bash, examine the contents of the record, and, if the record meets certain criteria, add it to an array. Basically, I want to filter records out of a CSV ...
0
votes
2answers
30 views

How does the shell decide which of same-name keyword, builtin, and external command to run? [duplicate]

When there are same-name builtin, keyword and/or external command, what is the order in which the Bash shell decides which to run? For example, keyword time and external command time, builtin ...
0
votes
0answers
12 views

Long response time when using chroot

I have a Ubuntu 14.04 LTS Server and yesterday the response time of the server was quite long, meaning when using simple commands like: ls -al it would take up to 20 seconds to respond in a very ...
0
votes
2answers
30 views

how to properly log the output of a console program that frequently updates “parts” of the screen, resulting in a messy log file?

I have some Java executable (jar) that is run my some shell script from a cron job once every night. That executable does not print log statements "as usual" just by printing them out in a sequential ...
3
votes
0answers
20 views

How to resize images to fit all content on minimal canvas?

I'm trying to quickly check for differences between separate iterations of a web site using ImageMagick's compare. But it refuses to compare images of different size, and doesn't seem to have an ...
2
votes
1answer
120 views

have I found a bug in BASH? [closed]

EDIT: the bug disappears by version 4.3.8. I am using GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu). I believe I have found a bug. Would like to know if perhaps I'm missing something ...
1
vote
2answers
58 views

How can a command in a pipe read from a keyboard? [duplicate]

I randomly tried to execute the following command in bash1 cat /some/file | ssh user@machine 'cat >/destination/file There are no keys installed on the remote machine, so the only way to ...
4
votes
5answers
61 views

execute command on a defined range of directories

Is it possible to 'partition' a directory listing - say in to blocks of some number, to perform different actions on each 'range'? For example, lets say I have the following directories inside ...
0
votes
2answers
34 views

Copying script files using wildcards

We have an SFTP location which is shared by two processes. Now we have a situation when we need to filter based on the filenames before copying. ClientA12345.out ClientA44378.out ClientB23478.out ...