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

3
votes
2answers
754 views

How to stop bash replacing commands in history with asterisks ? (‘*’)

I have some commands replaced with * in the bash history, e.g. 1094 apt-get update 1095* 1096 dpkg -i /var/cache/apt/archives/libssl1.0.0_1.0.0h-1_amd64.deb How to prevent this?
1
vote
1answer
21 views

Stopping jobs by PID?

Could someone tell me why I am unable to kill the jobs below when specifying their PID? I can stop the jobs when using their % id. Mac:~ gd$ ps PID TTY TIME CMD 4523 ttys000 0:00.02 ...
1
vote
2answers
33 views

Is it possible to have bash variables persist between runs

I am trying to create an init script which queries losetup -f for a free loop device. Within the init script I have a start() which queries losetup -f for the free loop device to setup some stuff, and ...
2
votes
3answers
40 views

How to pipe output from cat to cut

I want to cat /proc/uptime into cut -f1 in a Bash script. I've tried; cat /proc/uptime | cut -f1 cat /proc/uptime > cut -f1 cut -f1 < cat /proc/uptime Do I need to use echo or something ...
3
votes
2answers
52 views

Simultaneously check for empty output and successful exit status

I'd like to write the following test in an installer script1: if [ -n "`/etc/grub.d/30_os-prober`" ]; then install_dual_boot else install_linux_only fi However, it's also possible that ...
2
votes
3answers
71 views

How to determine if current locale uses UTF-8 encoding?

I would like to determine if the user's locale uses UTF-8 encoding. This seems a little bit ugly: [[ $LANG =~ UTF-8$ ]] && echo "Uses UTF-8 encoding.." is there a more general/portable ...
2
votes
5answers
145 views

Bash and its exclamation mark command, preview actual command before executing it?

! as a prefix to some string will execute whatever command in the command buffer that starts with the (partial) string given. There are also some other uses for it. See e.g. Understanding the ...
2
votes
2answers
56 views

universal help/man command: help builtin partial matches

I found a nice little script which iterates through a couple of manuals for a specific command. As a last resort, it will Google it and open a browser window. Source here: ...
8
votes
2answers
3k views

Does `Segmentation fault` message come under STDERR?

I ran an executable in bash ./code > log It shows occasional error messages on terminal whereas all printf statements go into log file. I re-run it like below ./code >& log Now, the ...
0
votes
2answers
43 views

Grep for regex in basename but return wholename

So say I have a list of files in a text file: ... /foo/barfoo /bar/foo/foobar /foobar/bar/foo ... I have a script that will search through this text file and, much like the locate command, I want ...
12
votes
3answers
547 views

How to customize Bash command completion?

In bash, it's easy enough to set up customized completion of command arguments using the complete built-in. For example, if, for a hypothetical command with a synopsis of foo --a | --b | --c, you ...
4
votes
3answers
27 views

Timing of ps piped to grep

So, this isn't a problem as such, just something I'm curious about. I'm using Linux Mint MATE which is branched off Debian. If I do: ps afx | grep abcdefg I get: 16599 pts/3 S+ 0:00 | ...
0
votes
1answer
27 views

Using curl with xargs connection hanging sometimes - any way to retry?

echo $LIST | xargs -I{} -n 1 -P 8 sh -c 'curl -o backup.dump http://url.com' I am running this for a large amount of files (around 300). After a while, sometimes curl hangs and won't progress for a ...
11
votes
1answer
807 views

'ls' showing two identical files in a directory

So somehow the command ls seems to be showing me two identical files in a directory. I am certainly not doing something right here. Behold $ ls -Blah /System/Library/LaunchDaemons total 32 ...
1
vote
1answer
58 views

Improving performance of script [closed]

I have been working on a script that can be used to automatically restart my Zabbix monitoring services in the event that they stop running. I have the script working just fine, but figured it could ...
1
vote
0answers
21 views

How can I modify a netinst.iso image to run a bash script on boot?

Background Using Fedora 21 with LVM on a Toshiba C50-B-021 laptop with UEFI (which from what I understand doesn't actually turn off), every time the computer runs out of battery it will hang on boot. ...
1
vote
2answers
47 views

How to print without formatting in bash?

printf "-Xdebug" Gives: bash: printf: -X: invalid option printf: usage: printf [-v var] format [arguments] echo -n "-Xdebug" works but according to this question here it isn't portable. There ...
3
votes
2answers
2k views

Get current terminal name

How do I fetch the current terminal name? I mean to the name that ps shows in the TTY column, e.g.: root@dor-desktop:/home/dor/Documents/LAMP_setup/webs_install/do/install# ps aux | egrep ...
1
vote
2answers
27 views

Capture Log file from multiple scripts

Im capturing all my script executions via the below command exec > $LOGDIR/myfile.log exec 2>&1 But the problem is my main script contains many other shell scripts(for different ...
2
votes
1answer
51 views

Who is the -bash executing user on my server?

On one of my servers I noticed there where 2 active users. Who is that second user? USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root tty1 10Feb15 ...
11
votes
2answers
12k views

Refresh aliases and functions after defining new aliases and functions?

When I define a new alias in .bash_aliases file or a new function in .bashrc file, is there some refresh command to be able immediately use the new aliases or functions without closing the terminal ...
18
votes
4answers
16k views

Is it possible to set Gnome Terminal's title to “user@host” for whatever host I'm connected to?

I'd like to set the terminal title to user@host so I can easily tell which machine I'm connected to from the window title. Is there a way to do this from SSH or from GNOME Terminal?
6
votes
2answers
866 views

Format cputime for ps

I'm trying to write a script that can monitor a process's CPU usage over an interval (to create a graph). So far, this is the command I'm using ps -p $PROCID -o cputime,etimes My only concern is ...
1
vote
1answer
35 views

How to add a new line before a specific string

I have a file like this (it shows in single line) Status: 012, Id: -1434606409zzzzz, Number: +9257884Status: 013, Id: -1434606409efwe, Number: +92465745Status: 014, Id: -1434606409fwe6, Number: ...
0
votes
1answer
37 views

Sort -u without sorting but with better uniqueness? [duplicate]

I don't want to sort my file, just filter out duplicate lines, maintaining the original ordering. Is there a way to use sort's unique function without it's sort function (something like cat -u would ...
16
votes
3answers
6k views

Recursive glob?

I'd like to write something like this: $ ls **.py in order to get all .py filenames, recursively walking a directory hierarchy. Even if there are .py files to find, the shell (bash) gives this ...
4
votes
1answer
34 views

can't run remote ssh command without heredoc

I can't get this command to work: user@server:~: ssh otherserver bash -ic 'source .profile; some-aliased-command' Variations I tried user@server:~: ssh -t otherserver bash -ic 'source .profile; ...
0
votes
4answers
38 views

How to remove 0 from the second column in a file

I ahve a script which fetches user name and mobile from a file in following format **Current Format** username mobile zzz 03333012345 123 03212334343 245 ...
5
votes
5answers
2k views

Why does grep not work with redirection?

Using the top command with redirection works fine: top > top.log Now I want to use grep to filter a certain line: top | grep "my_program" > top.log But the log file will remain empty. But ...
5
votes
5answers
4k views

Double and triple substitution in bash and zsh

Follow-up to the background part in this question. In bash I can use {!FOO} for double substitution, in zsh ${(P)FOO}. In both, the old-school (hack-y) eval \$$FOO works. So, the smartest and most ...
3
votes
1answer
124 views

Bash substitution with variable defined from a glob pattern

The below example explains the issue. Why is the FILENAME printed correctly when echoed and perceived as a pattern when using substitution? #!/bin/bash FILEPATH_WITH_GLOB="/home/user/file_*" ...
1
vote
1answer
33 views

Bash script to detect a file modified yesterday and check if its size is above a certain threshold

I'm writing a script to stat all files in a directory, and then find specific files that were created yesterday and tell me if they are larger than a certain size or not. So basically I need this to ...
0
votes
2answers
200 views

Why are there three syntax for setting variables in shell scripts?

root@ubuntu:~# echo ${x=1} 1 root@ubuntu:~# echo ${x:=1} 1 root@ubuntu:~# echo ${x-1} 1 root@ubuntu:~# Why are there three syntax for setting variables in shell scripts? What is the technical ...
1
vote
1answer
38 views

How to exclude command from history list, but to keep it in “live” history?

I've meanwhile managed to keep my history a lot cleaner thanks to you guys' great tips involving the HISTIGNORE option in .bashrc, omitting all those pointless ll or df -k lines. However, I've ...
-1
votes
0answers
28 views

bash script error - command not found

1 #!/bin/bash 2 #test integer2: evaluate the value of an integer 3 4 INT = 5 5 if [[ $INT =~ ^-?[0-9]+$ ]] ; then 6 if [$INT -eq 0 ]; then 7 echo "INT is zero" 8 ...
6
votes
2answers
6k views

How to grep the output of cURL?

I need to retrieve the expiry date of an SSL cert. The curl application does provide this information: $ curl -v https://google.com/ * Hostname was NOT found in DNS cache * Trying ...
4
votes
4answers
2k views

`openssl`: Subject Alternative Name

I wrote this bit of code to get the Common Name of the subject field in the SSL certificate for a given domain: $ echo -e "GET / HTTP/1.1\nEOT" | openssl s_client -connect google.com:443 2>&1 ...
1
vote
0answers
17 views

Problems with kpartx in a script

I am trying to run the rpi-image-creator script (see https://github.com/ImmobilienScout24/rpi-image-creator/blob/master/rpi-image-creator), and encounter some trouble with the kpartx use. The trouble ...
1
vote
3answers
78 views

Is there any way to print value inside variable inside single quote?

Consider I've set variable site and needs to be printed by echo or printf, but If I use single quote to write something and want to use variable then how? Example: $ site=unix.stackexchange.com $ ...
3
votes
2answers
167 views

How can I list bash's options for the current shell?

The bash intepreter itself has options, i.e. lines 22-23 of bash's man page: OPTIONS All of the single-character shell options documented in the description of the set builtin command can ...
1
vote
2answers
30 views

Scanning no: of characters of a file and write it that file itself

I have to scan the no of characters in a file and to write to that file itself with a hardcoded way like 99|EOF|. for eg: if a text file : test.txt is having abcd as text in it. count will be 4. So i ...
0
votes
1answer
20 views

Set the active tmux tab color

Is it possible to change the background of the active (current) tmux tab? I'm using tmux 1.9 on Ubuntu 15.04. $ tmux -V tmux 1.9 I tried to do: set-option -g pane-active-border-fg red But the ...
0
votes
1answer
26 views

php drop down menu to execute script with argument

I have shell script which I run like this /var/www/test.sh 2015 or /var/www/test.sh 2014 When this script runs, it actually takes data from freeradius and generates gnuplot base graph for the ...
3
votes
1answer
68 views

Filename Expansion: Find Utility Pattern Matching vs Bash Shell Pattern Matching

For filename expansion, the 'find' utility's '-name' option seems to function similarly, but not exactly the same as the bash shell's builtin pattern matching. Here are the relevant sections of the ...
1
vote
1answer
52 views

How can I make the unix `pass` program play nice with `ssh` inside the Linux Virtual Terminal?

I am trying to log into an ssh server by pulling the password directly out of the pass program without any GUI interaction. The normal workflow in the GUI (Gnome) is to do the following. Pull the ...
-1
votes
1answer
36 views

Prevent use of alias in script [closed]

I have a grep alias on my .bash_profile that display line numbers and color the matches. This is an example of my grep results: $ grep test filename 1:This is a test (to be removed) 1:This is a ...
84
votes
19answers
70k views

How can I get my external IP address in bash?

I need to find my external IP address from a bash script. At the moment I use this function: myip () { lwp-request -o text checkip.dyndns.org | awk '{ print $NF }' } But it depends on ...
2
votes
2answers
5k views

grep output of expect script

I'm trying to run some expect language, and grep/parse the output all in one script. I want to grep the output of and look for "error" (I should note that standard linux commands like awk, sed, grep, ...
2
votes
4answers
72 views

Change text in tag, but only tag is contained within a certain XML block

Using Git Bash, I'm trying to conditionally replace what's in the yrot tag in hundreds of files, but only if it belongs with a part name tag that pertains to wheel. // YES, change <part ...
0
votes
1answer
118 views

Possible to pass env vars into chpst without envdir?

I use runit to daemonize my web application, and I'm trying to see if I can have my process managed by sv not have to have a corresponding envdir for its environment variables. I wonder if I can just ...