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

10
votes
2answers
117 views

Correct behavior of EXIT and ERR traps when using `set -eu`

I'm observing some weird behavior when using set -e (errexit), set -u (nounset) along with ERR and EXIT traps. They seem related, so putting them into one question seems reasonably. 1) set -u does ...
1
vote
1answer
27 views

Set xterm title doesn't work over ssh

I followed unix s.e post and added the line, trap 'echo -ne "\033]0;$BASH_COMMAND\007"' DEBUG to my .bashrc file to set my last command as the terminal title. It works good on my ubuntu desktop ...
1
vote
3answers
94 views

String comparison in single brackets in zsh [duplicate]

Bash code to print all folders: for f in ~/*; do if [ $f == '/home/sk/.' -o $f == '/home/sk/..' ]; then true else echo "$f" fi done It works on bash. When i ran the code on z ...
1
vote
1answer
84 views

Why is Bash returning “No such file..” when pattern matching this string?

I have the following for loop: for f in ~/.lo-rcs/common/* do . $f done which is returning this error: bash: /home/sk/.lo-rcs/common/*: No such file or directory I keep classifying my bashrc ...
0
votes
0answers
31 views

Add slash suffix and not space for folder commands on bash auto-completion

What i expect my bash shell autocompletion to be like, % cd $HOM<TAB> -> cd $HOME/<CURSOR-HERE> What it does to me, % cd $HOM<TAB> -> cd ...
3
votes
4answers
136 views

Touching issue: Creating a filename from 2 variables

I am trying to create a filename from 2 variables. This is the error msg: touch: cannot touch `/root/tinstalls/2--06/06/15': No such file or directory 2--06/06/15 19:54 This is the code: ...
2
votes
0answers
47 views

Debian 8: Shell “service” command works quietly [closed]

I reinstalled Debian 8 Jessie on my vserver recently. I noticed an anomaly to previous versions: The service command shows no confirmation message anymore. If I want to restart e.g. the ssh service ...
0
votes
0answers
11 views

init.d/functions — get the program ids [duplicate]

This is the code block for function __pids_var_run, taken from CentOs - /etc/rc.d/init.d/functions # __proc_pids {program} [pidfile] # Set $pid to pids from /var/run* for {program}. $pid should be ...
5
votes
3answers
185 views

Assigning exit code to a shell local variable

#!/bin/bash function0() { local t1=$(exit 1) echo $t1 } function0 echo prints empty value. I expected: 1 Why doesn't t1 variable get assigned the exit command's return value - 1?
1
vote
0answers
41 views

set -x doesn't print stack info for bash autocompletion

In my bash 4.2.46 and centos - 7.1.1503, I ran set -x (to print debug info). Now, if I type ls, it prints: + ls --color=auto a b c ++ printf '\033]0;%s@%s:%s\007' root sk-vbox '~' All well and ...
0
votes
1answer
34 views

Custom bash prompt - cursor positioning issue [duplicate]

I know there are many related questions, however I couldn't find any other way to get help on this problem: On my CentOS VM I made a custom script for my bash prompt in /etc/profile.d/custom.sh ...
1
vote
1answer
52 views

Why does my bashscript not work?

So I made a bash script to automatically get ts3 installed and running on my vps, but for some reason it doesn't work. The error I get is: > /root/install/ts3install.sh: 4: cd: can't cd to ...
4
votes
5answers
89 views

Multiline Text Processing : Editing sshd_config

I have multiple blocks at the end of my sshd_config files like theses: Match User FOO ChrootDirectory /srv/www/FOO AllowTCPForwarding no X11Forwarding no ForceCommand internal-sftp ...
0
votes
3answers
47 views

What is `>&` in simple terms? [duplicate]

What does $ command 1>&2 do? As I understand it this runs the command but with the STDOUT redirected to the STDERR. But I'm not sure exactly how >& works. I have seen it as $ command ...
3
votes
1answer
134 views

How to log every command typed into bash and every file operation

I would like to log every command typed into bash (by either root or user) as well as every file operation. The idea is that I could write tools that could interrogate this log file and provide very ...
5
votes
1answer
53 views

How to stop a background process started in the same script, without exit the script?

I have a program that takes a variable time to run (no more than two minutes), and to make it less odious, I put fortune messages. #!/bin/bash ... for i in $(seq 1 45); do sleep 3; echo; echo; ...
0
votes
1answer
32 views

Can't run tmux although it's installed [duplicate]

I compiled tmux from source on Ubuntu 12.04 and it is installed in /usr/local/bin/tmux by default. However, when I type tmux in terminal I get the following message: $ tmux -bash: /usr/bin/tmux: No ...
0
votes
1answer
49 views

Why doesn't this simple piping with awk work? [duplicate]

I'm trying to follow this answer but I can't make it work. I simplified it down as much as I could to try work out what's going on (just running this at the terminal for now): rsync --progress -iav ...
2
votes
3answers
35 views

Local `set -e` for functions

Is there such a feature or can it be emulated reasonably easily? I want the same behavior except it should return where set -e would have caused a call to exit.
1
vote
1answer
26 views

Moving files modified after a specific date [duplicate]

How do you move files modified after a specific date (say 7 days for example) to another directory? I clumsily tried sending the output of ls -t | head -n XX But learnt recently that it isn't a ...
1
vote
0answers
17 views

List partition type GUID's for all disks from command line?

I need to list the partition type GUID's from the command line. Note: This is not the same as the partition UUID. Basically I'm needing to search for all disks that have the Ceph OSD type GUID: ...
1
vote
1answer
61 views

CentOS 7 - why the service file is not working to run my bash script?

How to make my bash script as service in CentOS 7? following is failing. $ cat /etc/systemd/system/mybash.service [Unit] Description=mybash Service After=network.target [Service] Type=simple ...
1
vote
0answers
17 views

How to get router info in “dhcp4-change” event in /etc/dhcp/dhclient.d/ script?

Am trying to add a script which will get executed on DHCP ip change for a particular interface. for that I have copied the below script at "/etc/dhcp/dhclient.d/dhcp-hook.sh". I need to get router ...
17
votes
6answers
517 views

dd-style parameters to a bash script

I would like to pass params to a bash script, dd-style. Basically, I want ./script a=1 b=43 to have the same effect as a=1 b=43 ./script I thought I could achieve this with: for arg in "$@"; do ...
2
votes
2answers
56 views

Copying new file and sending an email

I want to copy all files with the extension .beta from one directory to another and then send an email with following format. The following files have been moved from directory A to Directory B: 1. ...
1
vote
1answer
138 views

Create symlink - overwrite if one exists

I want to take down data in /path/to/data/folder/month/date/hour/minute/file and symlink it to /path/to/recent/file and do this automatically every time a file is created. Assuming I will not know ...
0
votes
1answer
44 views

Mailx -E flag fails

I am using mailx command with -E flag.This is what it says in man page for linux. -E If an outgoing message does not contain any text in its first or only message part, do not send ...
1
vote
1answer
46 views

Running a bash script on double click does not have all environment variables [duplicate]

I am running Debian. I have a jar file that I need to execute. A wrapper bash script does a java -jar MyProg.jar. The jar also calls some C code for which LD_LIBRARY_PATH needs to be set. I have set ...
0
votes
0answers
19 views

Export functions to remote or use NFS

We actually write some kind of audit tool for a large infrastructure. We just collect specific (system) information from remote systems in the network. For now, the setup of the tool looks like ...
0
votes
1answer
43 views

Host monitoring script with timestamp

I just made this script for host monitoring. The goal is to ping the host and log the output to a file but also to show output to the terminal. If the host is unresponsive it will log the time with ...
0
votes
0answers
17 views

su - with -s option and environment - why symbolic link doesn't work? [duplicate]

here's the trick: [root@aaa ~]# su - -s /bin/sh gerrit -c 'env' HOSTNAME=aaa JAVA_HOMEC=/opt/jdk/ SHELL=/bin/sh TERM=xterm-256color HISTSIZE=1000 JRE_HOME=/opt/jdk/jre/ USER=gerrit ...
1
vote
1answer
41 views

How can I make -e catch an error in a script within a script?

Lets say I have apple.sh set -e ...some commands #X... ./banana.sh ...more commands #Y.. and then banana.sh set -e ...some commands #Z... My expectation was that if an error was thrown somewhere ...
1
vote
4answers
43 views

What is the best way to delete files & folders in a directory excluding the contents of one folder? [duplicate]

I'm trying to automate some file house keeping I do pretty often. I want to delete all of the files and folders in a directory while excluding the folder "./xfer" and its contents. I've bee trying ...
3
votes
4answers
102 views

How do I get the value of a named option of an already running process in Linux?

I run the following command. ps -e -o args | grep destiny | grep UNIX I receive the following output. /path/to/destiny -r -m UNIX -t TCP -p 1501 What command can I use the get the value of the ...
1
vote
3answers
57 views

How to change bash prompt string in current bash session? [duplicate]

I have a following bash prompt string: root@LAB-VM-host:~# echo "$PS1" ${debian_chroot:+($debian_chroot)}\u@\h:\w\$ root@LAB-VM-host:~# hostname LAB-VM-host root@LAB-VM-host:~# Now if I change ...
1
vote
4answers
59 views

accessing loop variable within a loop

List = 1 2 3 4 5 for i in $LIST do sum=`expr $l_$i + $b` done here l_1, l_2, l_3, l_4 and l_5 are variables having some values. when I am trying to access those values within the for loop using loop ...
1
vote
0answers
15 views

How can you recover from disk corruption on a backup drive whilst maintaining all hard links?

So, I have a scenario that is similar to How to copy directories with preserving hardlinks? that I wish to use however I have corruption from the backup hardlink source. My Scenario: 1. I backup my ...
1
vote
0answers
17 views

Cross-session duplicate removal in bash command history

The problem context: always active ignoreboth and erasedups HIST_SIZE and FILESIZE with desired/practical limits of different history lines for our user almost always have multiple parallel sessions ...
2
votes
2answers
49 views

Bash input in the same line

My server is a Debian distro. I am currently configuring this bad boy up. In my Bash, I'm used to having the input to the command line being in one line, i.e.: root@my-server:~ $ cd .. ...
2
votes
2answers
74 views

How to create script which will enter password automatically? [duplicate]

I am creating a script. I want this script perform next task: Log in as a root user. (I am trying to use one line) How to create script which will enter password automatically? #echo "Hello Admin" ...
0
votes
5answers
108 views

How to grep an xml block in an xml file using a keyword in ksh

I have a file Sample.xml which contains a lot of services inside it and the structure looks like this Notes: I cannot use any XML parser tool as I don't have permission , read only My xmllint ...
4
votes
5answers
233 views

How to cut a date/timestamp String?

So I am using TIMESTAMP=$( stat -c "%y" $JARNAME.jar ) print $TIMESTAMP and its output is something like 2015-04-24 17:23:03.000000000 -0500 I need only the 2015-04-24 17:23:03 part
8
votes
2answers
448 views

Multiple shebangs in a single bash file

I have a script from other person which has a look (note: it's a single file): #!/bin/bash some commands some commands #!/bin/bash some commands some commands #!/bin/bash some commands some ...
4
votes
5answers
226 views

Testing if a file descriptor is valid

I'd like to make a bash script output additional information to file descriptors (FDs) greater than or equal to 3, when they are open. To test whether an FD is open, I devised the following trick: if ...
2
votes
5answers
148 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 ...
0
votes
2answers
43 views

Can't get if statement to run correctly. Beginner. [duplicate]

I am very new to bash, just playing around in my free time off work. I want to check if a file exists, and if it doesn't exists, I want to ask the user if they'd like to create it. Whether the user ...
0
votes
0answers
29 views

Computer won't load if I comment out sourcing bashrc from .profile? [duplicate]

I am trying to understand the difference/application of system files like .profile/.bash_profile/.bashrc etc. Now, I understand that .profile will be sourced when I login to the computer routinely ...
3
votes
0answers
64 views

Bash command not found due to stray garbage characters

What is the cause of this behavior? $ cd ../ $ bash: $'\210\210cd': command not found This happens sometimes (rarely) when I enter a command, there is no visible character preceding the cd, still ...
2
votes
3answers
88 views

determining column number using string in awk

Suppose I have a pipe separated file like: |Sr|Fruits|Colors| |1 |apple |red| |2 |orange |orange |3 |grapes |purple| Here it is evident using awk that, $2 is Fruits and $3 is the colors column. ...
19
votes
4answers
2k views

How can I delete a file named “>”?

I was running a Python script that malfunctioned and used sudo to create a file named >. How can I get rid of this file? Of course, when I try sudo rm >, I get the error bash: syntax error ...