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

3
votes
1answer
16 views

Bash script with conf file with unknown number of sets of variables

I am writing a bash script that has a configuration file. The configuration file will have sets of mode and mtu values. There can be zero or as many sets as the user defines. The bash script will ...
1
vote
2answers
39 views

Grep and ignoring leading whitespace

I've been working on a bash script to search for names of defines, and then grab the hex values for them and put them in the list. Once I have the list of names I'll attempt to search for "#define ...
0
votes
1answer
9 views

Sending special characters and new lines via KANNEL

Howto send message to kannel with lines and special character. Example if I have file message.txt which have following text line1 with few special characters like @ " / : line 2 spaces words etc line ...
1
vote
0answers
28 views

Drawing a histogram from a bash command output

I have the following output from a miRNA Predictor: Read Sequence:hsa-miR-576-3p MIMAT0004796 (22 nt) Read Sequence:gi|182396|gb|M74088.1|HUMFAPAPC Human APC gene mRNA, complete cds (8972 nt) ...
1
vote
1answer
18 views

Arrange program windows out of bash script?

I'm writing a shell script to automatically launch my work environment. It would be pretty nice to arrange the program windows automatically (for example vim opens at the left on desktop, and browser ...
0
votes
3answers
30 views

bc scale: How to avoid rounding? (Calculate small binomial probability)

Following code calculates the Binomial Probability of a success event k out of n trials: n=144 prob=$(echo "0.0139" | bc) echo -e "Enter no.:" read passedno k=$passedno nCk2() { num=1 ...
0
votes
0answers
25 views

How to scan for wireless networks fast

I have written a script which scans for wifi networks with iw dev wlan0 scan and put the SSIDs in a file. Is there a similar tool wich works a bit faster?
0
votes
1answer
23 views

How to copy files to the timestamp generated directory?

Hello I am trying to copy all files from Documents directory to the backup directory that has a timestamp. So I have created a directory called bk$( the time stamp of the directory) and I am trying to ...
1
vote
1answer
23 views

Calculate Out data Kb/s for specific PID

I have this command cat /proc/8221/net/netstat | grep 'IpExt: ' | tail -n 1 | awk '{ print $9 }' This shows me out bytes in that moment right? If yes, how can i show total kb/s in just one command ...
2
votes
2answers
33 views

Bash script function that changes the value of a variable

I'd like to make a function for a BASH script that changes the value of one of its arguments, that is a variable. The function that I did is: chck_rgx () { # Checks that the given name for a ...
2
votes
2answers
19 views

Is there a way to colorize output per stream from a program [duplicate]

I'm looking for a method to have bash colorize the output from a command based on what stream it was written to the terminal from. Is there any way to get it to colorize per stream? Like for example ...
1
vote
1answer
27 views

Get value of environment variable in for loop

I have several environment variable pam_branch app_branch worker_branch I use an array to define different projects and I want to get the values of these env var by rebuilding them in a for loop ...
2
votes
1answer
26 views

Dynamic Variable in KornShell Script

This KornShell Script (ksh): envir=Dev eval "${envir}foo=bar" echo "$Devfoo" Output: bar But I will not know what value is assigned to envir variable. So I want to do something like this where ...
0
votes
1answer
36 views

Bash : rewriting a file which is read in same line

I'm working on a bash script for partially automating router connection in command line. I'm a newbie in Bash. This is part where I have a problem: #!/bin/bash STRING2="ESSID" MYPWD=$(pwd) sudo ...
0
votes
1answer
22 views

Extract source commands of an existing gnome terminal session? [duplicate]

I have a bit of a situation. One of my co-workers just overwrote everyone's bashrc and bash_profile files. My custom settings have been lost. However, I still have a terminal open which sourced my own ...
2
votes
3answers
172 views

copy from file and paste in the terminal without x server

I have got an ubuntu linux without x server installed on it (cos it's only a gateway). I am requested by an application (ossec,-my question is not ossec related-) to paste information into the ...
3
votes
1answer
303 views

Add 30 days in date

Using bash or mysql , how can I add 30 days in user expiry table? Example I have DB name USERS and table expiry like this: USERNAME EXPIRATION JOHN 2015-09-26 I want the command to take ...
2
votes
2answers
266 views

How to copy and add prefix to file names in one step?

I want to copy and rename multiple c source files in a directory. I can copy like this: $ cp *.c $OTHERDIR But I want to give a prefix to all the file names: file.c --> old#file.c How can I ...
1
vote
1answer
66 views

Execute sh with parameters in bash

Hello I am newbie in bash and I am coding a daemon to execute a service. The syntax is ./ctlscript.sh start. When I execute service openproject start it should run this command, but it runs ...
2
votes
2answers
70 views

Bash: Rename file with prefix as suffix

I am trying to do something fairly simple and am a bit unfamiliar with how to accomplish this. I have a set of files that were named: x2_filename.png and would like to transform the file into this ...
2
votes
2answers
17 views

Using xfreerdp with variable IP/hostname [duplicate]

I got a very simple alias on my bash: alias xfreerdpp='xfreerdp /v:ip_address /u:username /d:domain /p:password /size:1024x768 /clipboard /cert-ignore &' All I want to do is to make the ...
2
votes
2answers
23 views

Tmux bash completion code walk-through

if [[ $COMP_CWORD -le $cmd_index ]]; then # The user has not specified a command yet local all_commands="$(tmux -q list-commands | cut -f 1 -d ' ')" COMPREPLY=( ...
0
votes
1answer
48 views

find files in a folder

I'm trying to make a FIFO script that keeps deleting files when disk usages reaches a limit. I have used the find command so that number of files wont be a limit to run the script. But I get an error ...
1
vote
1answer
123 views

Terminal closing on using 'login' command

I am using Centos 6.6. Whenever I use login <username>, the terminal shuts down. But when I use su - <username> it works fine. Also I tried doing the same on a SSH session and the session ...
0
votes
0answers
72 views

Bash, find and delete old files

Write script for backup files and delete old: #!/bin/sh BACKUPDIR=/var/backups/files ROTATE=1 mkdir -p $BACKUPDIR CURRENT="$BACKUPDIR/`date +%Y-%m-%d`-files.tar.gz" cd /var/ && tar czf ...
-5
votes
0answers
45 views

Error !! missig [: missing `]' please help [duplicate]

I an writing simple script in Bash, to check Linux file system disk usage on root file system and display a warning message if system is greater than 6%. The commands are running in a terminal, ...
-3
votes
4answers
71 views

Bash error: missing [: missing `]'

I an writing simple script in Bash, to check Linux file system disk usage on root file system and display a warning message if system is greater than 6%. The commands are running in a terminal, ...
12
votes
1answer
434 views

Why won't function return until background process ends?

Consider this script: #!/bin/bash function start { leafpad & echo $! } PID=$(start) echo "PID is $PID" The script does not continue past its closing brace until the leafpad process ends, ...
0
votes
0answers
31 views

why this file not modifying? [on hold]

sed -i "s/'${line[*]}'/'${newlinem[*]}'/" test2.txt I'm trying to replace whole line of my text file with new modified line. but my file not modifying with sed -i Both the above arrays are working ...
2
votes
5answers
288 views

Bash - Sequence of numbers in the same line

I know the command seq to generate sequence of integers, one per line, but I would like to ask two questions: Is it possible to write the numbers of the sequence in the same line? Is it possible to ...
2
votes
0answers
63 views

How to read result from the first step of parallel? [on hold]

QUESTION In bash you can pass data from step to step by piping data: program1 | program2 | program3 | ... Or you can do this with variables (depending how each program work): RES1=$(program1) ...
0
votes
0answers
18 views

Can I cheat the docker run -it session by remapping ctrl+p key?

This is regarding this issue with docker: https://github.com/docker/docker/issues/3519 and http://stackoverflow.com/questions/20828657/docker-change-ctrlp-to-something-else As I understand this, the ...
5
votes
1answer
178 views

Keep bash input on top line of screen

I'd like to keep the bash command prompt input at the top of the screen so that outputs from older commands are pushed downwards rather than up. How can I achieve this?
0
votes
1answer
44 views

Which are (bash) shell special parameters?

I've found some special parameter with bash starting with $ sign. Example: When I was wandering for exit status I knew about $?, process ID by $$ etc. So, I am sharing this post to know Which are ...
2
votes
2answers
111 views

How to check if the parent shell is interactive from a script?

I know that one can use the $- contains i or not or check if $PS1 is empty to tell if a shell is interactive. However, those solutions only work for the current shell. I have a bash script trying to ...
1
vote
1answer
58 views

How do I nest quotes four deep?

I have a complex command that I'm running in watch to nag users to get out of a filesystem when I need to unmount it. The following is working watch -ben5 $'lsof /mnt/unfs && ps --no-headers ...
2
votes
3answers
69 views

How to show the host name in Linux commandline prompt

I have several VMs and right now my command-line prompt looks like -bash-3.2$; identical on every VM, because it doesn't contain the host name. I need to always see which VM I'm on using hostname ...
5
votes
1answer
90 views

Bash script error: integer expression expected

I have a problem with a bash script on raspberry pi: x='gpio -g read 22' if [ $x -ge 1 ] then gpio -g write 23 1 fi The error is integer expression expected. Why?
0
votes
1answer
23 views

Howto prevent service down repeated email sent alerts via bash

I have a simple bash script scheduled to run every 10 minutes, which checks for the PID of any service, and if it is not found, it sends an email alert: #!/bin/bash if pgrep "mysql" > /dev/null ...
0
votes
2answers
32 views

BASH script to search for files in folders of 4 digits and older than 7 days

#!/bin/bash unset result result=$(find /home -path "$HOME/TestDir/[0-9][0-9][0-9][0-9]/test*" -mtime -7 -print -delete 2>/dev/null) [ "$result" ] || echo "There are no recovery files older than 7 ...
2
votes
2answers
43 views

find closest matching folder

What is the best way to sort the results of $ find . -name scripts -type d by the occurrences of '/' and then choose the first result. I want to create a function that would cd down to a common ...
0
votes
1answer
18 views

How to run `clear_console` in Bash when TMOUT happens?

How do I tell Bash to run a clear_console when the session is closed because of TMOUT?
1
vote
1answer
46 views

Get executable for any command [duplicate]

I want to know which executable gets executed for any command in bash. Example: I have firefox installed here /usr/bin/firefox, it is in the $PATH alias browser=firefox alias br=browser Now I ...
0
votes
1answer
39 views

bash script locked at if statement when executed

I am no expert with bash scripting. I am trying to understand why a bash script seems to stop its execution at an if statement. I have added echo statements in the scripts. I have a first batch ...
2
votes
1answer
37 views

bash on command event (or shell)

Is there a way to capture all commands executed in a bash or even better in sh? I need a wrapper script that gets called everytime a command is executed. Like when I type cd /home/ I want my ...
2
votes
1answer
26 views

Restart bash from terminal without restarting the terminal application (mac)?

I've looked around and bit for an answer to this question but I don't seem to find it (which is weird). My question is, is there any simple way to restart the bash session from within the terminal on ...
8
votes
7answers
2k views

How can I make a script to count up by fives?

I was trying to make a very simple bash script to list all of the multiples of five between 375 and 3500 (375, 380, 385...). One thing that I tried and didn't work is: for i in {375..3500} do ...
5
votes
1answer
193 views

Single parenthesis in bash variable assignment

So this might seem like a stupid question, but I kinda have OCD about this kind of stuff and I was wondering about single parentheses in bash. I know that they are used for executing commands in ...
3
votes
1answer
208 views

Loop through a multidimensional array in bash 4

I want to define a hash list in bash (version 4.3.30): 4 gateways each gateway has an IP an IP6 a name ... and I want to walk through this list in a loop and do stuff to each gateway. I ...
2
votes
2answers
91 views

Merge two-columns files into one file

I have a bunch of files (file1, file2,file3, ...) with two columns. For example, file1 looks like: 0.12 0 0.32 0 0.42 1 0.23 0 and file2 looks like: 0.34 1 0.55 1 0.31 1 0.99 0 I wonder how to ...