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

3
votes
2answers
35 views

Can terminal window titles be updated while a process is running?

I'm trying to set a little pomodoro/countdown timer for myself in the terminal. This comment on Superuser offers a handy little shell function that will act as a countdown timer, which printfs the ...
3
votes
2answers
36 views

Is there a shortcut to rerun a command with arguments from last command (not cd, ls or echo)

Searching through passed Logfile with something like this: cat /path/to/logfile | grep -iEw 'some-ip-address-here|correspondig-mac-adress-here' This gives me all the passed log lines until now so ...
2
votes
2answers
44 views

Command behavior is different when executed by an other user (via su -c)

I want to kill every processes who match a specific chain. Here is my script, which works pretty well: echo `ps aux | grep verySpecificChain | grep -v grep | /usr/bin/awk '{ print $2 }'` | xargs kill ...
10
votes
2answers
393 views

View a range of bash history

The history command lists out all the history for the current session. Like: 1 ls 2 cd /root 3 mkdir something 4 cd something 5 touch afile 6 ls 7 cd .. 8 rm something/afile 9 cd .. 10 ls 11 history ...
0
votes
2answers
27 views

Passing variables to script [duplicate]

What is the difference between: ./script.sh "$VARIABLE" and ./script.sh ${VARIABLE} Is there any?
1
vote
0answers
40 views

Smart case completion in Bash?

In Vim, one can combine the following commands, :set smartcase + :set ignorecase, to make searching case-insensitive unless there is a capitalized letter in the search query, in which case it is case-...
0
votes
0answers
53 views

I cannot type the letter 'l' in terminal on mac

I can type the letter L on any other applications except for within the terminal. I was wondering whether it would have something to do with the bash setting in .bashrc. I am running Ubuntu.
1
vote
2answers
49 views

parallel processing using xargs

How to execute a bash script in parallel for each line ? Actually, I will be tailing to log file and for each line found, I want to execute script in background something like below: tailf logfile....
2
votes
0answers
50 views

-bash: /root/.bashrc: Permission denied

I have this server running Centos 7. Every time I log in (remotely on locally) with every user I get an error. If i log as root I get -bash: /root/.bashrc: Permission denied If i log as a normal ...
0
votes
1answer
56 views

cat specific line range from /etc/hosts to dialog box

I need help with dialog box in bash. I like to list, for example all Ethernet switches from /etc/hosts and show them inside dialog box. After that I would like to connect selected switch from the ...
-8
votes
1answer
40 views

HOow to run hello world using bash? [closed]

Tell me how to run bash.i am new in this area please help me
1
vote
2answers
40 views

Defer variable expansion to subshell

My service uses environment variables extensively for configuration (mostly because it's really easy to inject those into a Docker container). I also have some maintenance scripts that I can run ...
2
votes
1answer
43 views

One of several file-append redirections of “python --version” is repeatably 'overlooked' by bash, but the others aren't [closed]

Why is bash consistently passing one, specific redirected output from python --version to the console rather than appending to file, while every other output is redirected properly? I am developing a ...
0
votes
0answers
53 views

Extract text above exception line in output [closed]

I have the following error output from a program: 2016-06-20 02:09:28,264 Mbr10063a cOqZeJiM BaseAction.java:getAlerts:618 ERROR [AlertAction] Could not open JDBC Connection for transaction; 2016-06-...
0
votes
0answers
25 views

Shell syntax var=${var:-$var2/file} [duplicate]

I came across the following syntax while working with some shell scripts. I am unable to understand what it does and I am not sure what should I search to get right documentation for this var=${var:-$...
23
votes
1answer
2k views

If “bash <file>” works, why is “source <file>” throwing an error?

I have the following script: #!/bin/bash set -x if :; then echo a fi If I run bash /tmp/file, a is echoed, but if I run source /tmp/file, I get: bash: /tmp/test: line 6: syntax error: ...
0
votes
0answers
43 views

First 0 of a number is being trimmed [closed]

I use this line to get the (unique) value from a file and use it as an argument in a bash script like so: casperjs script.js --num=`cat num` The script works well. Except that when the number ...
0
votes
0answers
19 views

Unable to test the presence of a substring [closed]

I was going through an online source and tried the following script echo "Please enter the name of a fruit" read fruit echo "You entered ${fruit}s" echo "The length of the <$fruit> variable ...
0
votes
1answer
120 views

Edit the editor in bash

Executing the fc builtin causes bash to fire up $FCEDIT on the last command. Because FCEDIT is a variable, this is inherently customizable. Is it possible to also customize the editor that starts up ...
0
votes
1answer
145 views

Echo semicolon in bash

I am trying to write to a file the following string: 1;2;3;4. The semicolons create problems. I have been able to figure out the following ecamotage to do it: variable='1;2;3;4' echo "${variable//;/\...
14
votes
4answers
1k views

How can I convert Persian numerals in UTF-8 to European numerals in ASCII?

In Persian numerals, ۰۱۲۳۴۵۶۷۸۹ is equivalent to 0123456789 in European digits. How can I convert Persian number (in UTF-8) to ASCII? For example, I want ۲۱ to become 21.
2
votes
1answer
118 views

Does pkill kill itself (and its parent processes) last?

I'm writing a bash script that kills a bunch of processes selected by certain criteria and then quits. The only problem is that those criteria apply to the script and its parent processes (bash, sshd) ...
0
votes
1answer
139 views

Check if date is n years old

I have a variable $date with format yyyy-mm-dd and I would like to check if it is exactly 1 year, 2 years (and so on) old. That's what I tried so far: dates=$(echo $date | cut -c6-10) todays=$(date +...
0
votes
0answers
33 views

How to transfer a big file simultaneously to several machines remotely? [duplicate]

I have launched 10 instances on a cloud service, and these are the steps that I want to do in parallel (simultaneously): 1) Copy a big input text file to each machine 2) Run a java program called ...
2
votes
1answer
119 views

How do I get bash to give a relevant error for a file with windows line-endings?

Suppose I have the following shell script: #!/bin/bash \n echo "Hello World" \n Running it gives Hello world. Now suppose I have the following shell script #!/bin/bash \r\n echo "Hello world" \...
1
vote
1answer
222 views

Why is my loop not continuing properly in my rock paper scissors game?

I'm making a bo3 rock paper scissors game. So far I've gotten it to work under every condition except ties. When a tie happens, it's meant to 'remake' that game by just subtracting 1 from I. It doesn'...
0
votes
1answer
108 views

What's wrong with my elif statements in this rock paper scissors game I'm making [closed]

making a rock paper scissors game to learn better bash. For some reason it's not liking my elif statements and I can't figure out why. Also if there are any better ways of doing this let me know, ...
1
vote
1answer
48 views

Can I check if create_ap works?

I am currently using the script create_ap to emit a Wifi Access Point (WAP) using my Raspberry Pi, which is running Raspbian. How can I check if the AP is up and running using a bash script? For your ...
2
votes
1answer
119 views

Read from and append to file at the same time while preserving end-of-line

Conceptually I have an easy task... I have [loosely] structured data in a file: Testing: debug, default CXXFLAGS <100's of additional output lines> Testing: release, default CXXFLAGS <100's ...
0
votes
1answer
121 views

Why does the factor command produce nonsense on an RSA modulus?

Ok, so I think I may have found a flaw in... something. I honestly don't know. This is such a weird scenario. I was attempting to break very small asymmetric (RSA) encryption, just as a Proof of ...
2
votes
1answer
51 views

Submit password with sudo and execute script with nohup

I would like to download and run a script in the background so the task is independent of the shell and its exit. Moreover this script should be run as sudo, using: echo MY_PWD | sudo -u MY_USER -S .....
3
votes
1answer
34 views

Capture output (sdout/stderr) of SSH port forwarder

I would like to store the error below in a variable: ssh -M -S /invalid/path/forwarder.socket -fnNT -Llocalhost:6301:remote_server:22 proxy_server muxserver_listen bind(): No such file or directory ...
2
votes
3answers
465 views

Pass output of “whereis” command to “cd” to change directory in one step

It should be simple no-doubt, but I can't find a way to pass output of whereis command to cd command in same line so I don't have to do cd in the second step. I have tried passing like below: cd $(...
5
votes
1answer
277 views

Why won't grep work in this command?

I have GTA San Andreas running in Wine, although when I exit the game it hangs in the terminal, and the process still has leftover resources, which causes it not to exit. So I've made this command ...
1
vote
2answers
23 views

Append a “finished” command after a specific command is used

I'm using Bash. I have a build command that I run a few times a day. I also have a command called "beep" that I use to alert me when a command finishes. So normally I do "build arg1 arg2; beep" and it'...
0
votes
1answer
22 views

how to load a bash alias for graphical terminal emulator

What I'm trying to do: Load an alias The alias: alias notes='cd ~/project/notes' My system: Ubuntu 16.04 and gnome terminal 3.18.3 In my home directory there are the following bash related files: ...
1
vote
3answers
45 views

Multiple logical operators, ((A || B) && C), and “syntax error near unexpected token”

I'm working with Bash 3, and I'm trying to form a conditional. In C/C++, its dead simple: ((A || B) && C). In Bash, its turning out not so (I think the Git authors must have contributed this ...
1
vote
2answers
62 views

Perl stripping substring with $ in front

I get that perl thinks the part of the string with $ are perl variables. What I'm trying to do with the perl call, is redefine variables preceded by a $ as \$, but that's throwing other errors. I ...
2
votes
1answer
134 views

specify shell for ssh session

I am logging to a remote server via ssh as user www-data. User www-data on the server has his default shell set to /bin/sh, and when I log in, I get dash as my shell. I can then type bash and get bash ...
3
votes
3answers
36 views

Proper type casting in bash script for use with while loop and modulus

I am trying to write a script to get a random, even hex number. I have found the the openssl command has a convenient option for creating random hex numbers. Unfortunately, I need it to be even and my ...
1
vote
2answers
46 views

sed: Grabbing and replacing all data between last backslash and a comma

I have data in a csv format that looks like this: F1309-042543,07/14/09 01:39:25,N/A,C:\windows\system32\netsh.exe,N/A,True F1309-042543,11/21/10 03:24:02,N/A,C:\Windows\System32\networkexplorer.dll,...
1
vote
2answers
46 views

Specifying comma-separated command line parameters based on text file lines

I want to run a command like: command argument --parameter=param1,param2,param3 where param1, param2, param3 may be any number of parameters coming from a file params.txt, each on one line. I can ...
0
votes
0answers
20 views

Ensure that file socket is already opened

I'd like to open a simple file socket that can run in background like: nc -l -k -m 10 -U my_socket -c cat & so other processes can connect into it with nc -U my_socket -c read. After this ...
3
votes
1answer
23 views

Can't use global shorcuts for Python applications

I'm using bash on a Mac. My problem is every time I try to run an installed Python application I just get a message that the command can't be found. Like so: -bash: gcloud: command not found Doesn'...
12
votes
1answer
253 views

Setting temporary bash aliases when entering a folder

Sometimes I like to have very customized bash aliases and maybe keybindings when I enter on a folder (can be a project where I'm used to type lots of commands from CLI). Lets suppose when I enter a ...
-1
votes
1answer
29 views

How to record numbers of array elements based on selection comparision criteria

I have many files which has many 2x2 arrays. In the present example I show only one file (file1) Input file(file1): 1: 6.1703 541.631 46.0391 2: 6.1930 537.446 45.9239 3: 6.1931 177.171 288.579 ...
0
votes
1answer
24 views

Bourne to grep and forward specific text from across a LAN

I'd like to develop a shell that keeps forwarding me the greped text(say compilation errors or warnings, in a single txt output) to some E-mail ID or on some NAS mount point, most importantly from ...
1
vote
0answers
24 views

Grid Engine for program that needs X11 but doesn't require user input

I have a bash script that calls an executable (some commercial software) in "batch mode". On the commandline, if X is available the program runs to completion and then quits, but if not the program ...