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

linux + get standart output from remote machine

is it possible to get the standard output from remote machine - 100 or 1 , after ruining the script /tmp/script.bash ? ssh $remote_machine /tmp/script.bash echo $? ( from remote machine script - ...
14
votes
5answers
1k views

How can I convert Persian numerals in UTF-8 to European numerals in ASCII?

In Persian numerals, ۰۱۲۳۴۵۶۷۸۹ is equivalent to 0123456789 in European digits. How can I convert Persian number (in UTF-8) to ASCII? For example, I want ۲۱ to become 21.
1
vote
1answer
38 views

Usage of `_` as an environment variable passed to a command

From bash manual _ At shell startup, set to the absolute pathname used to invoke the shell or shell script being executed as passed in the environment or ...
29
votes
5answers
33k views

Press space to continue

How do I stop a bash script until a user has pressed Space? I would like to have the question in my script Press space to continue or CTRL+C to exit and then the script should stop and wait ...
2
votes
2answers
29 views

Bash colors defined in .bashrc behaving oddly. I can't figure it out

When I type ls -l my command color defined in .bashrc is only used on the first item up until the directory or file name which has its own color defined. The proceeding lines seem to get a default ...
0
votes
3answers
33 views

Pad number within string and rename file [duplicate]

I have some filenames as such. a2.txt.gz d12.txt.gz k5.txt.gz m4.txt.gz ... one character followed by 1 or 2 numbers followed by .txt.gz. I would like to add single numbers with a zero before the ...
1
vote
0answers
29 views

What does `echo $_` output after `export foo=bar`?

This is from a comment at Understand the meaning of `$_` When I open a new tab in gnome terminal, I run immediately $ echo $_ EDITOR Is the output because the last line in ~/.bashrc is export ...
0
votes
2answers
55 views

How do I record all terminal input and output to a local file by default for each session?

I'm aware the script command can be used to record all keyboard input and screen output to a file, but this has to be invoked each time a terminal session is started. I keep timestamped versions of my ...
3
votes
1answer
22 views

How do I search bash's history in vi mode for “foo.*bar”

I have my bash environment in vi mode (set -o vi). So I can type <ESC>/ followed by a word, followed by enter, and bash searches for the word in the history. Since / is also vi's method to ...
3
votes
3answers
2k views

Query list of servers for memory/cpu allocated

Running RHEL 6.2, trying to write a bash script to SSH to a list of remote servers, and write the CPUs and Total Memory to a file, one line per host in the following format: HOSTNAME1 CPUS: 12 ...
2
votes
1answer
85 views

Reading a file with IFS loop works only when no arrays are used

Using the following code, I'm trying to read a file into an array: GROUPS=() while IFS=: read -r g1 g2 g3 g4 do GROUPS+=("$g3") echo "$g3" done < /etc/group This doesn't work, it doesn'...
0
votes
3answers
10k views

I don't see .bashrc file in my /home and /etc/skel direcories

I am running linux mint 17.1 rebecca, but I have found it quite different with other distros I am used to, in /home and /etc/skel there's no .bashrc I don't know if i mess up with something or it is ...
23
votes
4answers
97k views

how can I add (subtract, etc.) two numbers with bash?

I can read the numbers and operation in with: echo "First number please" read num1 echo "Second number please" read num2 echo "Operation?" read op but then all my attempts to add the numbers fail: ...
2
votes
0answers
55 views

“-bash: /root/.bashrc: Permission denied” when logging in

I have this server running Centos 7. Every time I log in (remotely or locally) with every user I get an error. If I log in as root I get -bash: /root/.bashrc: Permission denied If I log in as a ...
0
votes
1answer
18 views

joint two conditions in bash script

Note: Update Jun 28 I have an iptables script .sh (bin/bash) with the rules: function run_ips(){ for ip in $(sed '/#.*/d' ips.txt); do if echo $ip | grep -q "-" >/dev/null; then iptables -A ...
0
votes
1answer
10 views

creating shortcuts in Mac OSX at command line

I run a MacBook Pro with yosemite OSX. I'm trying to create shortcuts to go to certain directories, run script files, etc. This is my first attempt at creating shortcuts/aliases. I'm asking in this ...
2
votes
0answers
13 views

Exit status of fc -e is the wrong way around

I'm trying to edit and recall a previous command with Bash's built-in fc command, but somehow the exit status indicates failure on successful edit, even if that is a no-op. Demo: $ uname Linux $ fc -...
-3
votes
2answers
64 views

find all files excluding one directory

so I want to clean a directory before I start work. I looks a bit like this. ./static ├── css │   └── styles ├── img │   └── pictures └── js └── scripts I want to rm the contents of css and js ...
2
votes
1answer
150 views

Read from and append to file at the same time while preserving end-of-line

Conceptually I have an easy task... I have [loosely] structured data in a file: Testing: debug, default CXXFLAGS <100's of additional output lines> Testing: release, default CXXFLAGS <100's ...
1
vote
2answers
318 views

cpulimit on a bash script which runs other commands

I have a bash script which runs other cpu-intensive commands . When I apply cpulimit on the bash script, the output of top shows processes for the commands inside the script still run without ...
2
votes
3answers
730 views

Why does `bash -c 'echo $0 ' ` output “bash”?

$ bash -c 'echo $0 ' foo foo $ bash -c 'echo $0 ' bash From bash manual ($0) Expands to the name of the shell or shell script. This is set at shell initialization. If Bash is invoked ...
0
votes
1answer
54 views

Script wont return when executed via SSH

I am calling a script via ssh client like this: ssh root@host "su - oracle -c '~/bin/weblogic start'" The ~/bin/weblogic is a bash script that actually starts the web server in the background and ...
-2
votes
1answer
49 views

Why does `bash -c echo hello` not output anything, while `bash -c “echo hello”` output “hello”?

Why does bash -c echo hello not output anything, while bash -c "echo hello" output "hello"? Thanks.
1
vote
1answer
41 views

GNU Parallel: How can I reference array elements?

This is my case scenario: luis@Balanceador:~$ echo ${array[@]} a b luis@Balanceador:~$ echo ${array[1]} a luis@Balanceador:~$ echo ${array[2]} b luis@Balanceador:~$ parallel echo ${array[]} ::: 1 2 -...
0
votes
1answer
27 views

Unix command to return maximum float value out of two after subtraction

This is similar to question about getting the minimum/maximum of two numbers, but I'm interested to do the same with float numbers. So basically I'm trying to use shell arithmetic expansion using the ...
6
votes
1answer
94 views

Highlight current bash prompt line

I want the terminal to highlight the current bash prompt line. The effect I'm trying to acheive is the same as in text editors where the current line with the cursor is highlighted. Something like ...
38
votes
8answers
4k views

Why does Bash's source not need the execution bit?

with Bash's source it is possible to execute a script without execution bit set. This is documented and expected behavoir, but isn't this against the use of an execution bit? I know, that source ...
4
votes
5answers
1k views

List files with line count and date

I want to be able to list files showing the number of lines the each file has and the date. I can happily get the line count using wc -l *. Not a problem. I can get the date using ls -l. Is there a ...
13
votes
8answers
10k views

Is there a unix command that gives the minimum/maximum of two numbers?

I was looking for a command to limit numbers read in from stdin. I wrote a little script for that purpose (critique is welcome), but I was wondering if there was not a standard command for this, ...
62
votes
16answers
74k views

Is there a way to get the min, max, median, and average of a list of numbers in a single command?

I have a list of numbers in a file, one per line. How can I get the minimum, maximum, median and average values? I want to use the results in a bash script. Although my immediate situation is for ...
0
votes
1answer
26 views

What are the possible correct combination for std-out(2) and std-err(1)?

sqlite -echo test.sqlite < test44.sql > test44.out 1>&2. sqlite -echo test.sqlite < test44.sql > test44.out 2>&1. I used the first command to get an output of (stdout and ...
0
votes
2answers
31 views

bash: Why are () causing error in script but not on the command line?

If I type this on the command line: _longopt () { case "$prev" in --+([-a-z0-9_])) echo foo ;; esac; } it works as expected. If I put it in a script (foo.sh) it ...
0
votes
0answers
13 views

Arguments following `bash -c` [duplicate]

From Bash Manual, bash -c Read and execute commands from the first non-option argument after processing the options, then exit. Any remaining arguments are assigned to the positional ...
-4
votes
3answers
35 views

Bash - Print lines containing at least all vowels in any order but no consecutives [solved]

The problem is to write a script that takes a file as argument and prints all the lines that contain -at least- all the vowels , -regardless of ordering-, but with [no two same consecutive vowels]. e....
1
vote
1answer
34 views

Formatting issue

I have a small script like below, where output gets highlighted (in red,yellow etc) on screen if there an issue normal=$(tput sgr0) red=$(tput setaf 1) yellow=$(tput setaf 3) df -h >/dev/null 2&...
0
votes
1answer
28 views

how to get the standard output from command in variable

when we want to know what is the standard output of the ssh then we do ssh $linux_server "cat /proc/uptime" [[ $? -eq 0 ]] && ssh is ok but how to know the ssh standard output in case of ...
6
votes
3answers
7k views

How to permanently enable scl CentOS 6.4?

I installed a newer version of devtoolset (1.1) and was wondering how I would go about permanently setting these to be default. Right now, when I ssh into my server running CentOS, I have to run this ...
1
vote
3answers
218 views

Hide ones command history from other users on a Linux server

When I log in via ssh on a Linux(Ubuntu) server, I notice that all the bash commands executed by other users on the server are saved in the command history. Is there a way that could allow me to hide ...
1
vote
1answer
30 views

how to search file for begin of string and save a variable

i am trying to find a way of searching a file for string, it needs to work by searching then file and if any line in the file begin with what i am searching for, then take that whole line and save it ...
1
vote
1answer
7k views

rsh shows “poll: protocol failure in circuit setup”, why?

In the starting rsh worked properly, but after making some changes it shows some error [changes are shown in the end of this question, see that], I am sharing the same. Command $ /usr/bin/rsh ...
0
votes
1answer
56 views

Why isn't ~/.bash_profile executed when starting Ubuntu?

I installed Ubuntu in Virtualbox in a MacBook Pro laptop. In ~/.bash_profile, I added some directories to PATH. But after I reboot the guest Ubuntu, the added directories are not in PATH. I wonder why ...
-4
votes
2answers
131 views

z in bash script returns zero [closed]

#[ -z "" ] #echo $? returns 0 #[ -a "" ] #echo $? returns 1 except z all other alphabets throw 1 What might be the reason?
2
votes
1answer
40 views

Exit termite from within bash

I want to be able to completely close termite from within a bash script. I have something like this: while true; do read -n 1 -s result case $result in [c]* ) exit 0;; esac done ...
0
votes
0answers
35 views

How to Rename files in subfolders with subfolder name? [duplicate]

The directory structure is as follows: PWD/ A1/ acc.bam A2/ acc.bam A3/ acc.bam A4/ acc.bam All the acc.bam files should be renamed with subfolders names. For eg: "acc.bam" ...
0
votes
1answer
25 views

Some readline bindings not working

I'm tweaking with GNU Readline's key bindings in Bash. Specifically, I wish to achieve the following mapping effect: Control' ==> 'I' ControlShift' ==> "I" Control` ==> `I` Control[ ==>...
13
votes
2answers
12k views

How do I force a user to change a password at the first time login using ssh?

I'm trying to force a newly created user to change a password at the first time login using ssh. For security reasons I want to give him a secure password until he logs in for the first time. I did ...
1
vote
1answer
45 views

Extracting from Logs

Actual logs are: 2016-06-19 22:08:09 [213917] 1bEgCe-000tZR-E9 ** saadia@aol.com (fahad@manakintextiles.com) <fahad@manakintextiles.com> F=<james@designplus.com> P=<james@designplus....
10
votes
2answers
12k views

Printing decimal to ascii character, my command does not output as intended

I wanted to output a string of all the ascii characters with the following command for i in `seq 32 127`; do printf "%c" $i; done The output of the above command is: ...
2
votes
2answers
150 views

How to convert several tiff images into xyz coordinates in a single text file using the terminal?

I have limited experience with programming and Linux and I need your help. The situation I am in is that I have a stack of black and white .tiff images (approx. 400 of 10 Mb each one) which I need to ...