Questions specific to GNU’s Bourne Again SHell, as opposed to other Bourne/POSIX shells. For questions about Unix shells in general, use the /shell tag instead.

learn more… | top users | synonyms

0
votes
0answers
4 views

How to use bash command completion so that only files within a particular directory are completed?

Suppose I have a bash function specialcat that cats a file in the ~/Special directory specialcat () { cat ~/Special/$1 } Suppose the ~/Special directory was set up like so: mkdir ~/Special ...
0
votes
1answer
11 views

How to pass string with special characters to shell command in a script?

I'm writing a small script that will help me debug some permission problems. I am passing the parent folder I wish to examine and am able to specify any sub-folders which I want to ignore. I'm ...
0
votes
0answers
8 views

Sub process keyboard input layer

I have a bash script where I set up a stream playlist by user interaction. The user then press p to play the selection. This simply do something like: media-player --playlist media-player defaults ...
1
vote
1answer
23 views

Initilization script runs twice on SSH

Running Ubuntu 12.04. I have a script that sets up the environment, its run by /etc/bash.bashrc. (It may be set to run by other shell profiles inits, I didn't actually set it up myself) When I Ctr+...
5
votes
1answer
33 views

Go forward in bash argument history

I know about Alt + . to show the previous argument in bash. But what if I went past the desired argument (pressing Alt + . one too many times) and I want to go forward in history? Is there a key ...
1
vote
1answer
11 views

Conditional prompt for mercurial

I'm trying to have a prompt that looks like this: $ some-folder (patch-name): I was able to get that to work when I did the following: hg_ps1() { hg prompt " ({patch})" 2> /dev/null } ...
5
votes
4answers
218 views

bash + using printf in order to print in special format

I just wrote the following bash script to check the ping access on list of Linux machines for M in $list do ping -q -c 1 "$M" >/dev/null if [[ $? -eq 0 ]] then echo "($C) $...
0
votes
1answer
20 views

Expect Script - bash script file not found [on hold]

My expect script #!/usr/bin/expect -f #I tried replacing sh - with bash -s still no positive results spawn ssh xxxx@yyyy "sh -" < test.sh expect "password: " send "zzzzz\r" expect "$ " This ...
-1
votes
1answer
28 views

issue while running bash script remotely [on hold]

I created below script to take some backup.When i run it locally or by copying it to remote machine it is running fine. But when i ran it like: ssh asuser@isp2876 "bash -s" -- < AdvanceLog.sh ...
2
votes
2answers
34 views

Bash colors defined in .bashrc behaving oddly. I can't figure it out

When I type ls -l my command color defined in .bashrc is only used on the first item up until the directory or file name which has its own color defined. The proceeding lines seem to get a default ...
2
votes
2answers
91 views

Reading a file with IFS loop works only when no arrays are used

Using the following code, I'm trying to read a file into an array: GROUPS=() while IFS=: read -r g1 g2 g3 g4 do GROUPS+=("$g3") echo "$g3" done < /etc/group This doesn't work, it doesn'...
4
votes
1answer
33 views

How do I search bash's history in vi mode for “foo.*bar”

I have my bash environment in vi mode (set -o vi). So I can type <ESC>/ followed by a word, followed by enter, and bash searches for the word in the history. Since / is also vi's method to ...
0
votes
3answers
42 views

Pad number within string and rename file [duplicate]

I have some filenames as such. a2.txt.gz d12.txt.gz k5.txt.gz m4.txt.gz ... one character followed by 1 or 2 numbers followed by .txt.gz. I would like to add single numbers with a zero before the ...
0
votes
1answer
11 views

creating shortcuts in Mac OSX at command line

I run a MacBook Pro with yosemite OSX. I'm trying to create shortcuts to go to certain directories, run script files, etc. This is my first attempt at creating shortcuts/aliases. I'm asking in this ...
2
votes
0answers
21 views

Exit status of fc -e is the wrong way around

I'm trying to edit and recall a previous command with Bash's built-in fc command, but somehow the exit status indicates failure on successful edit, even if that is a no-op. Demo: $ uname Linux $ fc -...
1
vote
0answers
34 views

What does `echo $_` output after `export foo=bar`?

This is from a comment at Understand the meaning of `$_` When I open a new tab in gnome terminal, I run immediately $ echo $_ EDITOR Is the output because the last line in ~/.bashrc is export ...
0
votes
2answers
60 views

How do I record all terminal input and output to a local file by default for each session?

I'm aware the script command can be used to record all keyboard input and screen output to a file, but this has to be invoked each time a terminal session is started. I keep timestamped versions of my ...
-2
votes
1answer
49 views

Why does `bash -c echo hello` not output anything, while `bash -c “echo hello”` output “hello”?

Why does bash -c echo hello not output anything, while bash -c "echo hello" output "hello"? Thanks.
2
votes
3answers
737 views

Why does `bash -c 'echo $0 ' ` output “bash”?

$ bash -c 'echo $0 ' foo foo $ bash -c 'echo $0 ' bash From bash manual ($0) Expands to the name of the shell or shell script. This is set at shell initialization. If Bash is invoked ...
0
votes
1answer
27 views

Unix command to return maximum float value out of two after subtraction

This is similar to question about getting the minimum/maximum of two numbers, but I'm interested to do the same with float numbers. So basically I'm trying to use shell arithmetic expansion using the ...
0
votes
2answers
32 views

bash: Why are () causing error in script but not on the command line?

If I type this on the command line: _longopt () { case "$prev" in --+([-a-z0-9_])) echo foo ;; esac; } it works as expected. If I put it in a script (foo.sh) it ...
0
votes
1answer
26 views

What are the possible correct combination for std-out(2) and std-err(1)?

sqlite -echo test.sqlite < test44.sql > test44.out 1>&2. sqlite -echo test.sqlite < test44.sql > test44.out 2>&1. I used the first command to get an output of (stdout and ...
0
votes
0answers
13 views

Arguments following `bash -c` [duplicate]

From Bash Manual, bash -c Read and execute commands from the first non-option argument after processing the options, then exit. Any remaining arguments are assigned to the positional ...
0
votes
1answer
56 views

Script wont return when executed via SSH

I am calling a script via ssh client like this: ssh root@host "su - oracle -c '~/bin/weblogic start'" The ~/bin/weblogic is a bash script that actually starts the web server in the background and ...
1
vote
1answer
35 views

Formatting issue

I have a small script like below, where output gets highlighted (in red,yellow etc) on screen if there an issue normal=$(tput sgr0) red=$(tput setaf 1) yellow=$(tput setaf 3) df -h >/dev/null 2&...
0
votes
1answer
56 views

Why isn't ~/.bash_profile executed when starting Ubuntu?

I installed Ubuntu in Virtualbox in a MacBook Pro laptop. In ~/.bash_profile, I added some directories to PATH. But after I reboot the guest Ubuntu, the added directories are not in PATH. I wonder why ...
-3
votes
2answers
65 views

find all files excluding one directory

so I want to clean a directory before I start work. I looks a bit like this. ./static ├── css │   └── styles ├── img │   └── pictures └── js └── scripts I want to rm the contents of css and js ...
1
vote
1answer
30 views

how to search file for begin of string and save a variable

i am trying to find a way of searching a file for string, it needs to work by searching then file and if any line in the file begin with what i am searching for, then take that whole line and save it ...
0
votes
0answers
35 views

How to Rename files in subfolders with subfolder name? [duplicate]

The directory structure is as follows: PWD/ A1/ acc.bam A2/ acc.bam A3/ acc.bam A4/ acc.bam All the acc.bam files should be renamed with subfolders names. For eg: "acc.bam" ...
0
votes
1answer
26 views

Some readline bindings not working

I'm tweaking with GNU Readline's key bindings in Bash. Specifically, I wish to achieve the following mapping effect: Control' ==> 'I' ControlShift' ==> "I" Control` ==> `I` Control[ ==>...
1
vote
3answers
219 views

Hide ones command history from other users on a Linux server

When I log in via ssh on a Linux(Ubuntu) server, I notice that all the bash commands executed by other users on the server are saved in the command history. Is there a way that could allow me to hide ...
1
vote
1answer
42 views

GNU Parallel: How can I reference array elements?

This is my case scenario: luis@Balanceador:~$ echo ${array[@]} a b luis@Balanceador:~$ echo ${array[1]} a luis@Balanceador:~$ echo ${array[2]} b luis@Balanceador:~$ parallel echo ${array[]} ::: 1 2 -...
0
votes
1answer
28 views

how to get the standard output from command in variable

when we want to know what is the standard output of the ssh then we do ssh $linux_server "cat /proc/uptime" [[ $? -eq 0 ]] && ssh is ok but how to know the ssh standard output in case of ...
-4
votes
3answers
35 views

Bash - Print lines containing at least all vowels in any order but no consecutives [solved]

The problem is to write a script that takes a file as argument and prints all the lines that contain -at least- all the vowels , -regardless of ordering-, but with [no two same consecutive vowels]. e....
0
votes
1answer
46 views

How to compare two variables containing ipv6 addresses?

I have to compare two variables with ipv6 so there are strings and integers together. I tried it as below: if [[ "$ipvsrc" -eq "$ipvdst" ]]; then echo -e "Value OK"; fi error output was: ...
-1
votes
0answers
16 views

How to run a function for a specific received packet? [duplicate]

I am doing an experiment for my master thesis. I want to run a function (e.g. multiply two numbers) when a specific packet is received (e.g. a packet with destination TCP port 6666). For example, I ...
5
votes
1answer
230 views

Newline (“\n”) before output in bash

I want to modify my output in bash for better view of output. Simply put \n before this. How can I change it in .bashrc? For example: It's default: root@comp:$ abc bash: abc: command not found I ...
2
votes
1answer
32 views

How to suppress echo of buggy read function

I'm trying to capture a key press in a shell script (e.g. using read) and not to echo it. The three methods I found were stty -echo, the -s switch and stream redirection. However, on macOS, which ...
1
vote
1answer
27 views

Different command outputs

I entered same command with a variable host. During 2nd time I entered blank space between host,= and $. Why it was trying to connect to a server ? Also, when I write like $(host name), I am getting ...
3
votes
1answer
20 views

How can I escape an exclamation point in the PS1 environment variable?

It is substituted with the history number even if I try to escape it with a backslash.
4
votes
2answers
54 views

Compose string of IPs using bash command line

I have a command that returns the following: id1="172" id2="17" id3="136" id4="5" id5="0" /> id1="172" id2="17" id3="128" id4="2" id5="0" /> id1="172" id2="17" id3="128" id4="4" id5="0" />...
0
votes
2answers
36 views

Out-putting the results of a nested for loop to a file in bash

I am new to bash and I have been attempting to create a file out of my loop in bash , I was successful in generating the file with the following code for ((i = 0; i <= 5; i++)); do for ((j = i; ...
2
votes
2answers
40 views

Get only the size of a mounted filesystem

I want to get only the total size of a mounted filesystem. But the catch is that I only know about the mount point. So, I thought of using the df command. To get the size of this mounted filesystem, ...
1
vote
2answers
32 views

Generating strings of words with space delimiters from cut statement

I am new to bash. When I run the following command: grep "type" /root/myFile | cut-d'=' -f2 I get the following: 102 304 503 442 I want to store the contents of the first command into a ...
-1
votes
1answer
45 views

how to write own shell that works with ssh [on hold]

I tried several tutorials I modified usermod -s shell path_to_binary username it does not work thru winscp, but works if use from Ubuntu terminal I want to own shell, where I can control over ...
3
votes
2answers
752 views

Bash - “/” is a directory

This is really confusing... I currently have a Debian 8 computer, and I connect to it using PuTTY (SSH). The default console used is Bash. When I try to pass a path to an alias, it gives the ...
0
votes
0answers
29 views

How can I customize output of a command? [closed]

One of my friends asked me how to customize the output of a command & I thought a bit but I can't find an acceptable answer. ( For example adding * at the start of every output of the find ...
1
vote
0answers
14 views

Wacom Linux xsetwacom Attach Shell Script to Buttons

Using Inutos Pro with Manjaro. Would like to attach a shell/bash script to one of eight buttons. Script would be something along the lines of 'dolphin Documents'. Can xsetwacom do this?
0
votes
0answers
16 views

how to get a “parent-child” relationship with tmux panes and windows

Essentially I'm trying to mimic fork when I split a window or create a new one from an existing tmux session. For example lets say you enter a shell in gnome-terminal and then launch a new gnome-...
0
votes
1answer
19 views

PROMPT_DIRTRIM not working

I have the following in my .bash_profile: PROMPT_DIRTRIM=3 export PS1='$ \u in \w: ' However, when I navigate deep within a directory, the path doesn't shorten. This is what the prompt shows: $ ...