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

0
votes
2answers
53 views

how to extract lines between 2 patterns, and save them to different files

hej all, Let' say that we have this file: rrows 35 cols 51 spin 2 %band5 efermi=0.012538 0.004352 0.004317 0.004213 0.004047 0.003828 0.003570 0.003291 0.003011 0.002754 0.002544 0.002408 ...
0
votes
1answer
44 views

Files of specific extension in directory to be sorted by modified time and then stored in array

I have found many answers to sort the files of directory and even to save them in an array. Sorting Example ls -t Directory listing in array array=(*) My particular problem needs to sort files ...
0
votes
2answers
34 views

Linux Command Syntax not getting what is it

I am not a Linux guy but stuck in some Script which I have to read for my Project. So can anyone can help me what this command is doing? shift $(($optind - 1))?
10
votes
2answers
366 views

Differentiating between running and being sourced in a bash shell script?

Either what I'm asking here is extremely unorthodox/unconventional/risky, or my Google-fu skills just aren't up to snuff... In a bash shell script, is there any easy of way of telling if it is ...
2
votes
2answers
50 views

Can't login to server with SSH because of a script in /etc/profile.d exiting with exit status 1

so I have this problem, I can't login to my server with SSH. See: ssh -v myuser@myserver debug1: Authentication succeeded (password). debug1: channel 0: new [client-session] debug1: Requesting ...
5
votes
3answers
121 views

Output Output of command to command line directly, NOT variable

I am on the bash shell and I want the output of a command to appear directly in the command prompt that appears after the command has executed ! Example of what I envision it, to illustrate my idea: ...
-2
votes
1answer
37 views

ls: No such file or directory [on hold]

I have been messing around trying to install macvim to a higher version of 7.4. I finally got it working but now I get the error ls: No such file or directory when looking for a directory. I can ...
1
vote
2answers
46 views

Exporting a function from .profile/.bashrc

What am I doing wrong...? It's fine if I do this on the command line and then call it but not when I load it from .profile. Linux Mint Qiana, Bash 4.*, if it matters. function android() { command ...
-1
votes
0answers
28 views

Escape in awk invoked [on hold]

Using this line: sed -i 's/\t*$//' file_a > file_a I would need to incorporate in R in the system command (to execute it in a loop). I know that the escape is / but: system(paste("sed -i ...
5
votes
1answer
95 views

Logging bash output to a file

I'm trying to build vlc which is rather complicated and dependent on having the right packages installed, and keeps choking on errors. To trace all my steps I wish to output what I'm doing to a ...
10
votes
1answer
256 views

Why Ctrl+m and Ctrl+q wasn't used in bash shortcuts?

Recently I've been viewed through bash shortcuts key, and trying to find an appropriate one for my tmux activate key. And I find an interesting fact that ctrl + m and ctrl + q are not used in bash ...
3
votes
1answer
39 views

Parameter expansion in variable assigned with a wildcard

I have two files in my current folder (MA502) whose names are - MA502_TAAGGCGA-TCGCAGG_L001_R1_001.at.fastq MA502_TAAGGCGA-TCGCAGG_L001_R2_001.at.fastq I have many such folders - ex MA503, MA504 ...
13
votes
3answers
690 views

Can bash write to its own input stream?

Is it possible in an interactive bash shell to enter a command that outputs some text so that it appears at the next command prompt, as if the user had typed in that text at that prompt ? I want to ...
1
vote
0answers
21 views

-devilspie doesn't play nice with spawning new terminals

I'm trying to configure devilspie so that on detection of opening a certain directory it runs a script to mount that directory over a network. I don't think the script itself is too important but ...
2
votes
3answers
40 views

Split command and arguments, and put into variable in a bash script

I have a script that repeats the same (very long) grep command many times. I want to make the script more readable by cutting the line length, so I tried to put parts of the command into variables. ...
0
votes
2answers
54 views

breaking out of command loop but exit code not the reason?

I run the following: echo "while emacs;do echo $?;done;echo Exit code: $?;" | bash If I exit emacs through the menu or the close button, it prints exit code 0 and restarts. If I exit emacs through ...
-1
votes
1answer
38 views

Matching regular expression with delimited string in unix

Can someone help me in matching the below delimited regular expression in bash script: number|my_name|number I have tried the below but could not get it through end: sed -e 's/[^[[digit]]*//g
0
votes
1answer
19 views

Import list of IPs into DEVICE=eth0:X

I have a list of IPs I would like to import into my Linux VPS. They are not an IP range. How would I create a bash script that does this for me? 1.1.1.1 2.2.2.2 If they where my IP lists then it ...
1
vote
1answer
41 views

Display a line in a text file if variable matches a part in the line?

I'm making a stock checker. I have a file with all of the NYSE exchanges and their descriptions. The descriptions start on the first tab enter of the file. The file formatting looks like this: A ...
2
votes
1answer
30 views

View remote value of $PATH inside shell script

When executing this bash script, it only shows my local path. ssh ${REMOTE_HOST} 'bash -s' <<EOL set -e source ~/.profile echo $PATH # Commands here don't work because $PATH is ...
1
vote
2answers
62 views

Bash script with data from another file

I have worked on the following script which I want to use to easily add multiple Postfix as well as a few other things. Below is a small sample postmulti -e init postmulti -I postfix-$new -e create ...
0
votes
1answer
33 views

How to escape an input string in Bash [on hold]

I'm using the jq tool to handle some JSON in bash. Just one problem, while using this line: PB_ACL="acl="`echo $IMGREQ | jq -r'.data.acl'` Result: echo $PB_ACL // acl= The expected value jq ...
1
vote
1answer
38 views

Find last line of a file for matching string?

I want a loop that runs infinitely over a file but always checks the last line to see if it contains the matching string if it does then echo that line and keep the loop running. What I have right now ...
4
votes
1answer
69 views

Is there a command line tool to manage unix signals?

Is there a command runner like env, nice, nohup, etc., that can run a program with modified signals? In my case, I need something to reset SIGINT to SIG_DFL. Why do I need this? Because ...
0
votes
2answers
22 views

Saving a piped value went wrong

I installed jq to handle some JSON with bash. But somehow piping the JSON string to jq in combination with saving it's output to another variable went wrong. TEST='{"foo": "bar"}' PB_SIG=$TEST | jq ...
0
votes
0answers
13 views

How to get back my splitted screen after I lost connection

I was executing the screen command with a splitted window in my CentOS server then I lost connection to it. I reconnected to my server and I did screen -r to get my screen back but now I don't see ...
5
votes
2answers
280 views

Why does `cat` seem to iterate over JSON arrays?

I'm puzzled by this behaviour of cat when trying to output a heredoc containing JSON in bash 3.2: input: $ cat <(cat <<EOF > {"x":[{"a":1,"b":2}]} > EOF) output: {"x":["a":1]} ...
10
votes
3answers
774 views

How to understand “cat > file_name << blah” command?

In following command cat takes the content of here-doc and redirects it to file named conf: cat > conf << EOF var1="cat" var2="dog" var3="hamster" EOF How to understand the order of ...
0
votes
2answers
46 views

viewing printf after pipe (or subshell?)

Ok, this is hard to distill to a single question because it really depends on how I'm going to troubleshoot it. The following script is meant to pipe mount.cifs commands to a while loop that enters ...
0
votes
1answer
32 views

Python output in XML format

I have a python script which compare IP list with IP Database and gives output of matching criteria. (I got the script from this forum). convert.py #!/usr/bin/python import socket,struct ...
1
vote
2answers
29 views

How do I generate diffs for a series of files?

I have a series of a few thousand files, all with filenames in order, so let's say file1.x, file2.x, file3.x, etc. All these files are in the same directory. I know how to generate a diff from ...
2
votes
1answer
111 views

g++ bash: warning: programmable_completion: g++: possible retry loop

When I type g++ and do tab completion for file listing, I get this warning **g++ bash: warning: programmable_completion: g++: possible retry loop** I googled it and so far no results . Can ...
-1
votes
2answers
56 views

bash scripting and PS1 prompt

Im trying to customize the way the PS1 prompt shows in terminal and CLI on Arch Linux, but it's not printing the proper thing it should be doing. First up is I'm trying to colorize parts of the PS1 ...
3
votes
2answers
55 views

command substitution: /dev/stdin: Permission denied

Want to read whole stdin into variable. Don't want to spawn new processes. From bash manual: The command substitution $(cat file) can be replaced by the equivalent but faster $(< file). It ...
0
votes
1answer
42 views

Binary not accesible from Bash despite being in path

I am learning how to program in Racket. It's binary is in "/Applications/Racket v6.2/bin/racket". Let me show what happens: MacBook:~ enedil$ echo $PATH /Applications/Racket\ ...
0
votes
1answer
27 views

How to kill only current process and continue with shell pipe-line?

I have 2 related Doubts about Bash. (Q1) Consider tail -f SomeFile | wc, a fictitious command-line, where tail is used to simulate a command (C1) which runs for a long time, with some output from ...
3
votes
3answers
91 views

How to kill this process in bash

I am trying to interface my homemade Raspberry Pi-powered arcade machine with a coin acceptor, and for that I: use a shell script (named gameplay) which starts the game emulator (MAME) when a coin ...
-2
votes
1answer
37 views

Execute bash snippets directly in shell? [closed]

Is there any way to execute small bash snippets in the shell? If you don't want to edit a file again and again and test it by executing it again and again (in fact by jumping forth and back between ...
1
vote
2answers
24 views

bash command/script to reset default route

I manage several OpenWrt (embedded linux) routers for which I've written bash scripts to run an Openconnect VPN client. The client uses "vpnc-script" to set up routing, which replaces the initial ...
4
votes
3answers
276 views

Exiting a shell script with nested loops

I have a shell script with nested loops and just found out that "exit" doesn't really exit the script, but only the current loop. Is there another way to completely exit the script on a certain error ...
1
vote
2answers
34 views

how to use nohup while still sending stderr to the terminal

nohup automatically redirects stderr to stdout, but I want to send it to the terminal (it shows progress). How can I do that?
2
votes
1answer
36 views

Source .bashrc in zsh without printing any output

In the past, I've used bash consistently, because it's everywhere. But recently I started to try zsh. I don't want to give up updating my .bashrc fil which is rsync'ed to all my servers . So, in my ...
-1
votes
1answer
43 views

To sed if with and without conditions correct

I know that I may have the C package #include <stdint.h> in the first 1-30 lines. I would like to add it to lines where no previously if the file contains the word LARGE_INTEGER by GNU tools. ...
3
votes
2answers
55 views

How do I filter stdout of a program through grep while still controlling the program?

I'm trying to filter the output of the mpv media player, removing a particular line, but when I do so I am unable to control mpv with the keyboard. Here is the command: mpv FILE | grep -v 'Error ...
0
votes
0answers
15 views

Jumpimg between similar directories [duplicate]

My source and build directory structures are almost identical- /data/fs/src/lib/dedup/ /data/build/src/lib/dedup/ And I frequently navigate between them. It's painful to traverse up the parent ...
-3
votes
0answers
32 views

Detecting the newest file in a directory [closed]

I need a Unix script to do the following (in bash) : Accept 1 parameter; (the parameter can only be bo or bot.) Change directory (at this time, this can be determined yourself for now); Detect the ...
1
vote
1answer
59 views

How to get last N commands from history?

I want to see what are the last N commands in my history. I thought history | tail -n 5 would make it, but I noticed that a multiline command counts for as many lines as it has. $ echo "hello how are ...
1
vote
2answers
60 views

How do I get the output of a program already running?

I have a python program that outputs to stdout and a log file. However, the person I am making this for wants to know if I can set it up so that he can see the output of the file, while it is ...
0
votes
3answers
52 views

Bash: increment a variable in a while loop?

Bash newbie here! I have a bash script that for each file in a set, greps each line in the file for a string. Then it splits the line on commas, converts the 7th element to a float, and increments a ...
0
votes
0answers
18 views

Why is Debian's PS1 variable different from the other distros? [duplicate]

I've noticed that Debian's PS1 variable is a little different. For example: root@debian:~# echo $PS1 ${debian_chroot:+($debian_chroot)}\u@\h:\w\$ What is this part: ...