Tag Info

New answers tagged

0

It seems, you messed up /etc/profile. Normally PATH is defined in /etc/profile and $HOME/.profile.


0

Though the ioctl(,TIOCSTI,) answer by Stéphane Chazelas is, of course, the right answer, some people might be happy enough with this partial but trivial answer: simply push the command onto the history stack, then the user can move 1 line up the history to find the command. $ history -s "ls -l" $ echo "move up 1 line in history to get command to run"


0

Traditionally bash functions are placed in ~/.bashrc as this is read by interactive bashes. ~/.profile is only read by login bashes. New windows usually dont run login bashes.


9

Use script(1) to log everything sent to the terminal: $ script Script started, file is typescript $ # do your work ... $ # then exit with ^D $ exit Script done, file is typescript You can later look at the output with less: $ less -r typescript Beware that the logs will contain all control characters sent to the terminal, such as ANSI colours or ...


11

Ctrl+M sends the same character(RET) as the Enter key in terminal. Programs have no way to tell them apart, so these keys cannot be configured separately. Ctrl+Q is already used for XON by default, so it cannot be used by Bash, but you should still be able to use it in tmux, because tmux uses raw input mode. A GUI program could read from the keyboard, that ...


1

A way to do this that includes (IMHO) the best parts of the other two answers is to write a shell function that embodies all the functionality that you want to be invariant, and takes arguments specifying the things that you want to be different on different instances: my_rsync_grep() { rsync -av --delete -R "$1" "$2" "$3" | grep -E '^deleting|[^/]$' ...


2

The command Forward=*R1*.at.fastq sets the variable Forward to the string *R1*.at.fastq (star, capital R, digit 1, star, dot, lowercase A, etc.). Wildcards are only expanded in contexts that allow multiple words; the right-hand size of a variable assignment expects a single word, so no wildcard expansion occurs. In a command like cat $Forward, the wildcards ...


14

With zsh, you can use print -z to place some text into the line editor buffer for the next promt: print -z echo test would prime the line editor with echo test which you can edit at the next prompt. I don't think bash has a similar feature, however on many systems, you can prime the terminal device input buffer with the TIOCSTI ioctl(): perl -e 'require ...


1

Bash source code says that there are too many completion retries. Bash Reference Manual says: It’s possible for shell functions executed as completion handlers to indicate that completion should be retried by returning an exit status of 124. If a shell function returns 124, and changes the compspec associated with the command on which completion is ...


12

It depends on what you mean by bash only. If you mean a single, interactive bash session, then the answer is almost definitely no. And this is because even when you enter a command like ls -l at the command-line on any canonical terminal then bash is not yet even aware of it - and bash isn't even involved at that point. Rather, what has happened up to that ...


1

RTFM: while The syntax of the while command is: while test-commands; do consequent-commands; done Execute consequent-commands as long as test-commands has an exit status of zero. The return status is the exit status of the last command executed in consequent-commands, or zero if none was executed. If you want to acquire a return value from ...


2

The usual way is to make only command's arguments as variable _mn=/backup.raw/ _rscmdarg='-av --delete -R' _greparg='-E "^deleting|[^/]$"' _rslog=/var/log/rsync.log as $_rslog is a file, and $_mn a dir, it is okay to keep them. and the "final" line is: rsync $_rscmdarg --exclude=alternatives /etc/ $_mn | grep $_greparg >> $_rslog


3

The splitting into different parts (command & arguments) does not work if variables are used. Use eval for this case: eval $_rscmd --exclude=alternatives /etc/ $_mn | eval $_grep >> "$_rslog" In general, it is better to use shell functions or aliases than using variables: alias my_grep='grep -E "^deleting|[^/]$"' ... ... | my_grep >> ...


0

Your while loop evaluates on a boolean value. In this case you could also read it as while true or while 0. So if emacs returns another value like 1 if it is killed the loop ends.


0

Here is what I would replace your script with: #!/bin/bash while read new ip domain do postmulti -e init postmulti -I postfix-$new -e create cd /etc/postfix-$new rm -rf main.cf wget http://www.********.com/*******/main.zip unzip main.zip mv main main.cf echo -e "queue_directory = /var/spool/postfix-$new" >> /etc/postfix-$new/main.cf ...


1

There is no. Very easy to write one with perl. Here's untrap script: #!/usr/bin/perl $SIG{INT} = "DEFAULT"; exec { $ARGV[0] } @ARGV or die "couldn't exec $ARGV[0]: $!"; Example usage: #!/bin/bash untrap bash -c ' sleep 3 echo aaa ' & trap '' INT wait $! If you remove untrap prefix, Ctrl-C won't kill the script. More versatile script: ...


1

you mean you are searching for patterns in a file not matching. Use grep -v for that. grep -v "^[[:digit:]]\+|[^|]\+|[[:digit:]]\+$" <input But basically you are asking about how to write regular expressions. Read regex(7) for that and keep in mind that each command uses other quotation rules for special characters. But most basic linux commands use ...


1

Here is one solution - #!/bin/bash grep "^$1 " NYSE.txt NASDAQ.txt | sed 's/:/ /' | awk '{printf "Stock %s ( %s ) - ",$2,$1; for(i=3;i<NF;i++) printf "%s ",$i OFS;if(NF)printf"%s",$NF;printf ORS}' The first grep searches for the line that starts with symbol. The sed substitutes the ":" after file name from get output to a blank space. The awk ...


2

Here you go: counter=`ls -1 /etc/sysconfig/network-scripts/ifcfg-eth0:* 2>/dev/null | cut -d : -f 2 | sort -n | tail -1` if [ -z "$counter" ] then counter=0 fi for ip in `cat iplist.txt` do counter=`expr $counter + 1` cat << EOM > /etc/sysconfig/network-scripts/ifcfg-eth0:${counter} DEVICE=eth0:${counter} BOOTPROTO=static ONBOOT=yes ...


3

The $PATH is getting expanded prior to running on the remote server. Example #1 Say I run these commands from a system called skinner.bubba.net. [root@skinner ~]# ssh mulder 'bash -s' <<EOL > echo $HOSTNAME > hostname > EOL skinner.bubba.net mulder.bubba.net By moving the single quote so that the echo $HOSTNAME is inside it, you can ...


0

You can do something like: while read line; do new1=$(echo $line | cut -d"," -f1) ip=$(echo $line | cut -d"," -f2) domain=$(echo $line | cut -d"," -f3) <Your bash script here with above three variables> done < file.txt I hope it helps ..


0

I've since tried tackling the problem from a different angle, using the 'expect ' command. However the following fails to work: #!/usr/bin/expect spawn sudo mount.cifs "//192.168.1.2/My Pictures" /home/pi/Desktop/Pictures -o user=Rob_ expect "Password: " { set send_slow {1 .1} send -s "a_password" } It responds to the password prompt by typing it ...


1

Missed a space: PB_ACL="acl="`echo $IMGREQ | jq -r '.data.acl'` ^


0

#! /bin/bash echo "Script is starting......." FILE="/Users/shubhamsinha/Desktop/new_test.log" STRING="MYNAME" while true; do tail bar | grep "MYNAME" && echo "FOUND" && break sleep 5 done Example FILE="/home/user1/tmp/bar" Script name is foo % ./foo & [1] 12586 Script is starting....... ...


1

Not an answer, but a formatted comment: $ cat <(cat <<EOF > {"x":[{"a":1,"b":2}]} > EOF) bash: warning: here-document at line 15 delimited by end-of-file (wanted `EOF') bash: warning: here-document at line 15 delimited by end-of-file (wanted `EOF') {"x":[{"a":1,"b":2}]} Put the closing parenthesis on a new line $ cat <(cat <<EOF ...


-1

There are multiple reasons: Your debug printf didn't work, because mount prints its prompt to the terminal, not stdout. read prompt failed and the loop was never entered. You are trying to echo the password to /dev/stdin. This will not work, you can only read from it. the mount's stdin is still connected to the terminal. There is no way to emulate user ...


1

Use this with bash: TEST='{"foo": "bar"}' PB_SIG=$(jq '.foo' <<< "$TEST") echo "$PB_SIG" Output: "bar"


0

Try this on the second line: PB_SIG=`echo $TEST | jq '.foo'` The two problems I see is that you need to echo the $TEST variable's value through the pipe and that you need to capture the output of the piped command.


8

This is just shell variable expansion by bash. In this context whatever is between the curly braces will be iterated and expanded into the expression. $ echo var{1,2,3,4} var1 var2 var3 var4 $ echo var{1..10} var1 var2 var3 var4 var5 var6 var7 var8 var9 var10


0

You don't specify which operating system this is for; if it is Linux, and given that you're interested in monitoring a specific process, you might find it more worthwhile to parse /proc/$PROCID/stat - see the proc(5) manual page for details.


15

Here-Document is a kind of shell redirection, so the shell will perform it as normal redirection, from beginning to the end (or from left to right, or order of appearance). This's defined by POSIX: If more than one redirection operator is specified with a command, the order of evaluation is from beginning to end. In your command, cat will perform ...


-1

When bash creates the process to run cat, it opens conf for write on file descriptor 1 and opens a temporary file (for the here-document) for read on file descriptor 0, before execing the program. In this case, it doesn't really matter in which order those actions happen. Order does become significant when file descriptors are reassigned, e.g. with ...


0

If you can't edit /etc/sudoers file. follow this. it worked for me. cd /etc sudo su visudo -f sudoers


11

Well, let's find out: unset file cat >"$file" <<EOF this is not in ${file=./myfile} EOF bash: : No such file or directory Dang. I guess it must be doing the >"$file" part first then. But what if...? unset file <<EOF cat >"$file" this is in ${file=./myfile} EOF ...no error...? cat ./myfile this is in ./myfile As it ...


2

The printf command performs implicit iteration if it is given more arguments than conversion specifiers. For example: $ printf "%s-%s\n" 1 2 3 4 5 6 1-2 3-4 5-6 There are two conversions, but six arguments. So three repetitions of the formatting logic occur, marching over the arguments pairwise. With that we can do: printf "10.0.0.%s\n" $(seq 1 23) ...


3

There is the prips utility which generates an IP list from a range or CIDR. Useful for work with large ranges: $ prips 10.0.0.20 10.0.0.23 10.0.0.20 10.0.0.21 10.0.0.22 10.0.0.23 $ prips 10.0.0.0/23 10.0.0.0 10.0.0.1 10.0.0.2 <...> 10.0.1.254 10.0.1.255


0

You don't those /dev links to do this. I know sudo will purge environment variables, but you can still pass variables through in the form of arguments since you're calling another shell anyway... sudo -u nobody bash -c ' a=$1; echo "$a" ' -- "$(echo aaa)" ...or... echo aaa | { sudo -u nobody bash -c ' a=$1; echo "$a" ' -- ...


2

This example assumes, all the csv contents are lying in a file named a.csv...you can change it to use stdout stream instead of file stream and out of laziness, i put longitude, latitude as sub-elements.. you can put them as attributes as well from xml.etree.ElementTree import Element, SubElement, Comment, tostring top = Element('markers') f = ...


0

I'm not sure if this is exact answer, but at http://linuxcommand.org/lc3_adv_tput.php I found several functions testing tput for colorizing BASH. I hope it helps. #!/bin/bash echo "tput colors test" echo "================" echo echo "tput setaf/setab [0-9] ... tput sgr0" echo for fg_color in {0..7}; do set_foreground=$(tput setaf $fg_color) for ...


1

The following shell script, when given an argument of the form file1.x, generates a series of diffs. It increments the last series of digits in the file name (so you can start at file0.x or file42.x) and goes on until it finds a missing number. #!/bin/sh current=$1 suffix=${1##*[0-9]}; digits=${1%"$suffix"} digits=${digits##*[!0-9]}; ...


0

While it's not that hard to replicate, your screenshot likely came from tldp.org; the bottom of that page contains a script that outputs the table you see: To help myself remember what colours are available, I wrote a script that output all the colours to the screen. Daniel Crisman has supplied a much nicer version which I include below: #!/bin/bash # # ...


1

First off, there is not a clean solution to your problem without reimplementing some key component of how the shell (bash in this case) deals with history. Below is a solution that maintains your local history so that the arrows work as expected. Ctrl-r in turn is bound to searching your global history. The solution depends on an excellent utility for ...


2

The following script takes an argument like "file*.x" and applies it to find | sort to get a list of files to process. With thousands of files, you may get "too many arguments" by echo file*.x. #!/bin/bash prev= find . -maxdepth 1 -type f -name "$1" | sort -V | while read -r file; do file=${file#*/} # Remove leading ./ if test -n ...


0

First, my suggested solution is presented below. After this, each of the two errors that you observed are discussed. Suggested Solution Bash variables cannot hold a NUL character. Consequently, it is only possible to read an entire file into a bash variable if the file contains no such characters. Subject to this bash limitation, the following should ...


4

Lets start with two simple cases: attempt 1: PS1="\$" This does not work for root. Why? The double quote and the backslash. You need one of the next two lines. PS1='\$' PS1="\\$" OK, so that fixed the the dollar sign issue. Now lets look at the fun with alignment and color: Attempt 2, set the color to default: PS1='\033[0m\$' You will notice that ...


1

Problem Personally, I hate that Wiki page, because some of the pieces are missing, namely what to do after you fix the colors, and distinguishing between the root and user prompt. Note that the steps below apply a system wide prompt, ie every user will see colors. Fix Taken from 3 ways to pimp your BASH console, which links to the same page you ...


3

It seems that you have made a mistake when editing PATH variable. Backslash character in your PATH output was considered literal, not escaping for space. You need: PATH="/Applications/Racket v6.2/bin:$PATH"; export PATH or: PATH=/Applications/Racket\ v6.2/bin:$PATH; export PATH


1

There's something odd going on with the command line - whether it is a file-system problem or something more elementary (like unprintable characters in a directory name). The error message "Unable to find a suitable output format for pipe:1" is due to the previous "-f flac" being ignored. I have tried renaming an mp3 to your stated problem filename, and ...


0

For a more general approach to killing processes... This command should show the process pgrep -f runcommand.sh Then either cut and paste the process ID kill PROCESSID or, if you're a little braver using pipes pgrep -f runcommand.sh | xargs -I{} kill {} If you don't have pgrep (for some reason), then you can replace the pgrep command with this ...


0

The command stty -a will show you all keyboard shortcuts. The only signals mapped are Ctrl-C (SIGINT), Ctrl-\ (SIGQUIT) and Ctrl-Z (SIGSUSP). There is no binding to other signals. I would use the solution that you yourself said: separate shell, psoutput and killthe process you need killed. To your second question, it is not because of the grave accents ...



Top 50 recent answers are included