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
0answers
18 views

Installation Bash Files

When Linux is installed, (I assume) a bash script is used to mount the drive, install packages, etc. etc. If I wanted to install more packages upon installation, what directory would the script to ...
2
votes
1answer
23 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
32 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
16 views

Extract source commands of an existing gnome terminal session?

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
68 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
282 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
212 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
61 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
65 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 ...
1
vote
2answers
14 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
46 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
67 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
68 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, ...
11
votes
1answer
420 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
233 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 ...
1
vote
0answers
56 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
17 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
176 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
43 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 ...
1
vote
3answers
65 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
87 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
31 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
40 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
17 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
38 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
192 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
88 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 ...
0
votes
1answer
23 views

Loop commands to network daemon?

I'd like to feed a network daemon using a loop! To be more specific: There is a network daemon listening on localhost:portx. The daemon expects me to guess a PIN between 0000 - 9999. I want to use ...
-1
votes
2answers
37 views

Create shell script to remove certain files from specified directories

I am looking to create a simple script that does the following: cd /specified/directory cd into child directory only if it has a 4 digit name e.g 1234 rm -r all files that begin with letter P rm -r ...
3
votes
1answer
44 views

Possible to pipe command using su via ssh

I'm trying to write a python script to remotely update the login passwords for a set of account I administer - I can already successfully use python to pipe remote commands via the stdin of an ssh ...
0
votes
1answer
49 views

Bash script strange behavior - script does not act as manual commands

So, this is strange. When I manually run commands it all works fine, but when I run a script with identical commands, I get strange error output. This is what I run: lxc list; for elem in ...
1
vote
3answers
32 views

What does it mean to run a process in background? [duplicate]

What exactly does it mean to run a process in the background? The difference between $program and $program&: Is it just that the input file descriptor is not inherited from the shell or is there ...
3
votes
4answers
377 views

Add path to $PATH if not already in $PATH [duplicate]

I need to add a path in a bash script, but it may be executed several times: export PATH=${OPENSHIFT_HOMEDIR}/app-root/runtime/bin/:${PATH} I don't want that path to be added over and over. How can ...
3
votes
1answer
66 views

Bash: Permission denied when trying to echo data directly to Network

I am trying to send characters directly to the network stack as explained in this thread. Even when the process work OK under CygWin (Windows), the same lines do fail on Ubuntu v14.04: ...
7
votes
2answers
62 views

bash: how to propagate errors in process substitution?

I want my shell scripts to fail whenever a command executed with them fails. Typically I do that with: set -e set -o pipefail (typically I add set -u also) The thing is that none of the above ...
1
vote
3answers
31 views

Bash prompt string appears in same line as curl command output

When I run a curl command, the json response that it returns collides with the bash prompt string: ~$curl localhost:8001/api {"message":"this is a test message"}~$ Notice ~$ at the end of second ...
1
vote
2answers
47 views

Returning an variable from a function

I have the Linux script from bellow. I can get to return from the method decrypt nothing in order to unzip a file. The method decrypt sends a string with the name of a zip file. Please give some ...
-8
votes
1answer
59 views

replace the the first line of all .sh files in a folder

Create list of all .sh files in current folder. Check first line of each file in this list and if file starts with #!/bin/sh then replace that with #!/bin/bash. Only modify files that have #!/bin/sh, ...