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

6
votes
4answers
17k views

bash: /home/user/.ssh/authorized_keys: No such file or directory

Create a ssh key: $ ssh-keygen -t rsa –P "" Moving the key to authorized key: $ cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys bash: /home/user/.ssh/authorized_keys: No such file ...
2
votes
8answers
3k views

How to print lines with blank 5th field in CSV

I have to check if the fifth field is empty in a CSV file. This is my file: 1,abc,543,87,DATA,fsg; 1,abc,543,87,,fsg; 1,abc,543,87,DATA,fsg; 1,abc,543,88,,fsg; 1,abc,543,,DATA,fsg; As you can ...
0
votes
1answer
28 views

Remote execution of a file is not working

I'm trying to execute a local file (here /tmp/cmd) on a remote machine (slc05bkt) using SSH. Here's the command I'm trying from a script file: cmd="ssh -v ssuthari@slc05bkt \"bash -l -s\" < ...
2
votes
0answers
53 views

Why does this pipe not end when the las process dies (zombie)?

I have a script run and monitored by svscan/supervise. When the last luces-hf/run: #!/bin/bash set -v export http_proxy=[redacted] curl -N -s https://[redacted] |\ grep --line-buffered "event" | ...
21
votes
6answers
2k views

Why does [A-Z] match lowercase letters in bash?

In all shells I am aware of, rm [A-Z]* removes all files that start with an uppercase letter, but with bash this removes all files that start with a letter. As this problem exists on Linux and ...
0
votes
2answers
11 views

Bash parameter expanstion to remove tabs

I've got such a line in script: TATVAR=$(echo $PARAMVAR|sed -e 's/^[ \t]*//') I'd like to shrink this to not to execute additional program (sed), shellcheck suggested to me that i should use: ...
0
votes
3answers
30 views

Shell Script to change locale has no effect

I wrote a simple script to switch my locale. If I write each line in the console and execute it, it works without any problem or if I put it in .bashrc. However when I execute the script either with ...
8
votes
1answer
6k views

Trap, ERR, and echoing the error line

I'm trying to create some error reporting using a Trap to call a function on all errors: Trap "_func" ERR Is it possible to get what line the ERR signal was sent from? The shell is bash. If I do ...
3
votes
3answers
159 views

Help with bash script

I am teaching myself bash scripting with the book 'Learning the Bash Shell' by Newbam. I'm getting on OK with the book, but am a bit confused by the following script. It is a script which uses a for ...
-1
votes
1answer
28 views

error while changing directory using crontab [on hold]

This is my script I am trying to rename the files in folder. rename1.sh ---------- #!/bin/bash cd /home/lanein1/WestonIN7pm/"$(date +%Y-%m-%d)" && rename s/WestonIN/WestonIN7pm/ *.jpg cd ...
1
vote
1answer
35 views

Pass list of directories (that contain whitespaces) to a command in a script

For example, I want to execute the following within a shell script: tar cvpzf /destination/backup.tgz /directory\ one /directory\ two I wish to assign the list of paths (with whitespaces in them) ...
6
votes
3answers
69 views

tell if last command was empty in PROMPT_COMMAND

In bash, from inside PROMPT_COMMAND, is there a way to tell if the user just hit 'return' and didn't enter a command?
0
votes
2answers
14 views

Find line within file matching pattern and make a substitution

I'm trying to simplify my life here but I'm stuck. I have a file containing multiple lines. Each line has a user and a number. I'd like to know a bash one-liner to search for a user and change the ...
1
vote
2answers
101 views

How to script with systemd-cgtop?

The manpage for systemd-cgtop says that if there is no attached tty it will do one iteration and then print it out, saying that this would be useful in scripts. However when I try to do this from a ...
0
votes
3answers
106 views

How would an administrator of a system prevent himself access to a file for 24 hours?

How would a single administrator go about locking himself out of a file for 24 hours? By "lock" I mean prevent access. I have removed the 'rules' placed on the original post, as it is clear that the ...
1
vote
1answer
25 views

Start new bash session background

Is it possible to create a command called new_bash that allows me to do the following? new_bash alias test="ls" new bash alias new_command="ls" new_bash test file1 new_bash new_command file1
3
votes
1answer
32 views

How to revert from searching to original command

Following the instructions here, I edited by .bash_profile to enable the up and down arrows to autocomplete what I have typed in the shell based on previous commands. I added to my .bash_profile: # ...
7
votes
4answers
14k views

How to do an IF statement from the result of a executed command

I am trying to do an IF statement from the output of an executed commmand. Here is how I am trying to do it, but it doesn't work. Does anyone know the right way to do this? if [ "`netstat -lnp | ...
4
votes
3answers
77 views

I have accidentally broken /bin/bash

I just started using Linux. I'm using Ubuntu and I think I made a very grave mistake. I made a script and by some stupid sense I decided to move it to my /bin folder, but I accidentally typed mv ...
0
votes
1answer
18 views

safe way to redirect some output using exec

I have a script that is rather "noisy". I've been asked to clean up the output so that most of the script's output goes to a log file, and the user just sees the start-up message, and the message when ...
6
votes
4answers
16k views

How do I kill all screens?

I accidentally created over 1000 screens. How do I kill them all with one command? (Or a few)
0
votes
0answers
8 views

AFP share with local Unix users

I have a Solaris server on which I have a AFP share. I connect from a Mac client to that AFP share with local users from the Solaris server. So let's say I connect to the share with the Alice user. ...
0
votes
1answer
21 views

How to create a custom command in Linux for a wine pdf application?

I'm using Debian GNU/Linux 7.8 and would like to have PDFXCview.exe as the standard application to open pdfs. Opening a pdf using a small executable file including #!/bin/bash wine ...
7
votes
7answers
28k views

bash - replace space with new line

How can I replace spaces with new lines on an input like: /path/to/file /path/to/file2 /path/to/file3 /path/to/file4 /path/to/file5 etc... To obtain the following: /path/to/file /path/to/file2 ...
15
votes
2answers
3k views

grep inside less?

I'm currently sifting through a lot of unfamiliar logs looking for some issues. The first file I look at is Events.log, and I get at least three pages in less which appear to display the same event ...
3
votes
1answer
580 views

How to call a shell script from Javascript code?

I am not able to call a shell script program from javascript(for example if someone will click a button in webpage then a script will run and will throw some output)???
4
votes
5answers
2k views

Bash Script to Sort Files into Alphabetical Folders on ReadyNAS Duo v1

I have an old ReadyNAS Duo v1 (Sparc) running an unknown flavour of Linux. I have a folder structure with 1,000+ files I want to move into a folder structure based on the first letter of the file ...
4
votes
1answer
660 views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
3
votes
5answers
192 views

How do I *reliably* and *simply* get the current shell interpreter name?

I'm looking for a simple and reliable way to get the name of the current shell from inside a script or a sourced file (not from the command line). I would have expected to just do $(basename ...
2
votes
3answers
92 views

List transient files by numerical value having number greater than a given constantly varying filename

I've a directory having constantly changing filenames (by numerical value) listed as: -rw-rw----. 1 root root 10493952 May 7 10:39 A0000000.LOG -rw-rw----. 1 root root 10493952 May 7 08:38 ...
6
votes
2answers
76 views

Notification Listener Behaving Strangely when Backgrounded

I've been struggling to get my IRC-Bouncer/Notification Script working. This is meant to be a script which will automatically login to a remote machine, attach to a screen session (or start one if ...
4
votes
2answers
1k views

Cygwin: readline lib loaded in different locations

Within cygwin, almost each unix command I type prints a warning message, takes time and eventually gives a correct result: -bash-4.1$ ls 0 [main] bash 7468 child_info_fork::abort: cygreadline7.dll: ...
20
votes
3answers
505 views

What does 'exec {fd}</dev/watchdog' do in Bash

That is literal, {fd} isnt a placeholder. I have a script that does this, and does not source in anything, nor does it reference {fd} anywhere else. Is this valid bash? exec {fd}</dev/watchdog
4
votes
2answers
825 views

Creating an alias to Change Directory and have that directory be the current working directory in new terminal tabs

I'm trying to create a convenience alias that will change directories and then start a node server in that directory. I have it working for the most part, there's just one little issue that I can't ...
0
votes
1answer
38 views

What means echo“{@@##}”?

We got a script that we need to understand, and at some point, we got this syntax: if [ "$PASS_CHAINE" = "TRUE" ] then echo "Launching DEGAGEMENT" | SLog cd $INTERFACE_D/bin_cm/deg ...
7
votes
3answers
6k views

Get path of current script when executed through a symlink

I have a utility consisting of a couple directories with some bash scripts and supporting files that will be deployed to several machines possibly in a different directory on each machine. The ...
0
votes
1answer
21 views

Queue up multiple videos from Bash Script

-Skip to bold to skip the fluff - I'm new to ubuntu, so still learning the ropes of how bash scripting goes. I've got this code I've been working on, which works great. (side question - can I ...
1
vote
1answer
22 views

OSX: Delete all matching certificates by command-line

Using shell script to delete all matching certificates. I found a list of certificates using: security find-certificate -c "certificatename" -a -Z|grep SHA-1|awk '{ print $NF }' Output is like ...
3
votes
3answers
13k views

How to calculate values in a shell script?

I run this command in the terminal: grep "bla bla blah" blah* | echo "Blah: $(wc -l) / $(ls | wc -l) * 100" And I get this output: Blah: 44 / 89 * 100 What I expect to see: 49.4 Is there a ...
8
votes
4answers
652 views

bash loop with 0.02 increment

I want to make a for loop in bash with 0.02 as increments I tried for ((i=4.00;i<5.42;i+=0.02)) do commands done but it didn't work. I appreciate if you help me out.
-2
votes
1answer
36 views

Restrict bash command for specific user [on hold]

I just searched on this page, but the answer does not meet my idea. My idea is when user called Bob access ssh and run a command, for example sudo apt-get update, then the bash sheell will respond ...
3
votes
1answer
30 views

chkconfig does not support my script

I have looked and looked and none of the threads I have found are helping. We have a tomcat startup script that we modified slightly for our needs. It works fine on Centos / redhat 6 boxes, but does ...
0
votes
1answer
68 views

Why is sed coming back with “unterminated `s' command”?

So I have a Bash script which looks like this: #!/bin/bash extentemplate=" exten => `$prevchannel`,n,Queue(`$prevchannelname`)\ exten => `$prevchannel`,n,Hangup()\ \ ;`$channelname`\ exten ...
1
vote
1answer
32 views

Provide three argument to one option using getopts in bash

I am trying to process a command line using getopts in bash. I have to pass three arguments after -w option. For example, -w 1 do loop. It should print one line before and after each line from loop ...
-1
votes
0answers
27 views

how to move directories by date to cooresponding monthly directoires

using bash, how would one move directories with a common name, by create date to a monthly corresponding directory without calling out the source specific create date? #!/usr/bin/bash $SourceDir ...
19
votes
8answers
5k views

How to efficiently generate large, uniformly distributed, random integers in bash?

I have been wondering what would be the best way to get good randomness in bash, i.e., what would be a procedure to get a random positive integer between MIN and MAX such that The range can be ...
0
votes
1answer
14 views

How to create a module on a CentOS cluster [on hold]

I would like to create a module on a CentOS 6 cluster (e.g. module load gcc-4.7.2). Basically, I have no clue how modules work. Are there any good tutorials illustrating this or could someone ...
1
vote
4answers
94 views

Show ratio for all availiable resolutions

I tried to get the ratio with this script: echo "$(xrandr)"|cut -f 4 -d" "|sed 's/x/00 \\\* /g'|while read i; do echo "$i = "$(expr $i); done but I get errors like 102400 * 768 = expr: ...
1
vote
1answer
3k views

Proper escaping of double quotations for curl post data?

I'm trying to test out a server, by sending it JSON data and reading the response. I need to POST data like {"item":"value with spaces"} but when I use curl I find that it sends the backslashes as ...
2
votes
3answers
110 views

Log both stdin and stdout of program

What I want though is to run a program and log both the stdin and stdout, but I want the stdin to be supplied from a file. I thought script log.txt < input.txt would work, but it does not, because ...