The tag has no wiki summary.

learn more… | top users | synonyms

7
votes
4answers
2k views

Press space to continue

How do I stop a bash script until a user has pressed Space? I would like to have the question in my script Press space to continue or CTRL+C to exit and then the script should stop and wait ...
0
votes
1answer
146 views

ssh with for loop - parentheses problem

I have the following script: while [ "$1" != "" ] do case "$1" in -h) HOST="$2"; shift 2;; esac done if test -z "$HOST" then [...] else TODAY=$(date +'%Y-%m-%d') ...
0
votes
1answer
927 views

is there a “goto” like command in ksh

Here is my script: #!/bin/ksh #this is where I want to go again if user enter #an answer other than "yes or no" echo "yes or no?" read ans case $ans in [yY]*) echo "yes" ;; ...
3
votes
1answer
239 views

How to execute a Bash comand and execute two statements on failure?

Ì want to execute a Bash command, followed by two actions if and only if the test returns an error. I would prefer to solve this task as a one-liner in Bash. Here are the two forms I have tried: ...
4
votes
3answers
265 views

Bash: handling “[[ statement ]] || echo problem found ; exit 1” logic

In the statement in the title, there is a problem that even if the statement is true, it will still exit with status 1 because, as I understand it: [[ statement ]] || echo problem found ; exit 1 ...
3
votes
1answer
99 views

Bash to print out the make result

To compile my project and to check if it's good or not, I want to print out the status message after make command. Which one should I use? make && echo “Success” || echo “Fail” make || echo ...
5
votes
5answers
276 views

shell script to control the number of processes of an user

I have to launch a total number, NUMTOT of a program (could be any, C, Mathematica, ns-2... mathematical environments). The problem is that the computer where these processes run only admits a ...
1
vote
2answers
292 views

Shell: Break both if and for loop at once

Shell: Break both if and for loop at once. My script: ip to name resolve code IP=192.168.27.191 hostNameChecker() { if [ `getent hosts $1 | wc -l` -ne 0 ];then HOST_NAME=`hostname` ...
5
votes
3answers
2k views

Loop through the lines of two files in parallel [closed]

The object of the script I'm making is to compare two series of files. The file names are themselves stored into two separate files, one path per line. My idea is to have two while read loops, one for ...
8
votes
2answers
371 views

tmux not respecting disabled control flow

In my shell I have flow control disabled using stty -ixon. This works perfectly in the shell and when I launch tmux and start programs within tmux. However, when starting a new session from the ...
2
votes
4answers
404 views

bash while loop that breaks at a given file size

So, I bought this book called Primes and Programming, and it's pretty tough going. Today I wrote this (simple) program from chapter 1: #!/usr/bin/env python import math def find_gcd(a,b): while ...
5
votes
2answers
162 views

[ vs [[ : which one to use in bash scripts? [duplicate]

The zsh man page, in its section on test (aka [), explicitly advises against using it at all, and urges readers to use [[ whenever possible. The relevant section states: The command attempts to ...
4
votes
1answer
5k views

do…while or do…until in POSIX shell script

There is the well known while condition; do ...; done loop, but is there a do... while style loop that guarantees at least one execution of the block?
5
votes
2answers
958 views

Requesting user input while reading file line by line

For class I need to write a Bash script that will take the output from ispell and when I try and request user input inside the while loop it just saves the next line of the file as the user input. ...
2
votes
1answer
2k views

In a Bash Script how does the continue command work with embedded loops?

I am writing a bash script in a busybox session. The script has to initiate an external executable numerous times in sequence in daemonised form then monitor the output. while read LINE; do ...
4
votes
1answer
5k views

shell backup script, missing `]`

I'm putting together a simple backup script that will tar contents of a folder, then move that file to a backup server. The script makes sure that the tar file exists and is not zero bytes before ...
2
votes
3answers
2k views

Can I do ssh and do for loop and touch files in a single shot?

for account in ${accounts} do `ssh -q id@server "touch EVENTS_${account}_${date}.log"` done Instead of doing ssh so many times, can I just do ssh and run the for loop and touch the files?
4
votes
3answers
305 views

How to pipe to multiple places with vertical bar?

I have a folder full of files with a .dot extension like this: a.dot b.dot c.dot I want to go through all the files in this folder and run a command on them such as this: dot -Tpdf a.dot -o a.pdf ...
3
votes
2answers
1k views

Keep global variables values piping through functions

I wrote a little bash script using sed on some html pages to extract some urls. To avoid each time grabbing sed results in a variable then read it again I simply made 3 functions and piped together. ...
4
votes
2answers
529 views

Why does this shell snippet to check if hosts are up using netcat stop prematurely?

Q: Why does the second iteration exits after 10.175.192.16? Can someone explain that? Or I just found a "while/netcat" bug? a.txt's content: $ cat a.txt 10.175.192.14 10.175.192.16 10.175.192.17 $ ...
3
votes
3answers
398 views

Multiple Command List After Shell Conditionals, &&, ||. Shell Script, Dash

I'm trying to do multiple commands after a condition, so for example... [ $VAR ] || echo "Error msg" ; echo "exit" and the Inverse [ -z $VAR ] && echo "Error msg" ; echo "exit" I know ...
1
vote
2answers
208 views

conditional expression and expansion

I don't seem to understand how to "test" the conditional operators [[ and [. I tried using various form such as echo [[a=a]] [[a=a]] echo $? and some other things I want to see what they ...
7
votes
4answers
8k views

How do I reverse a for loop?

How do I properly do a for loop in reverse order? for f in /var/logs/foo*.log; do bar "$f" done I need a solution that doesn't break for funky characters in the file names.
6
votes
2answers
270 views

Send task to background in an “if”

Why is this? if true; then sleep 3 &; fi bash: syntax error near unexpected token `;' I want to run sleep 3 in the background so that the command ["sleep 3" is just an example] would run ...
7
votes
2answers
349 views

Why does 'for anytext; do' loop four times?

Is this a bug or a feature? It seems to happen for unquoted alphanumerics. Running GNU bash, version 4.1.5 for alpha01234; do echo $((++i)); done output: 1 2 3 4
12
votes
2answers
7k views

Confusing use of && and || operators

I was skimming through an /etc/rc.d/init.d/sendmail file (I know this is hardly ever used, but I'm studying for an exam), and I've become a bit confused about the && and the || operators. ...
14
votes
4answers
15k views

How to conditionally do something if a command succeeded or failed

How can I do something like this in bash? if "`command` returns any error"; then echo "Returned an error" else echo "Proceed..." fi
3
votes
1answer
516 views

Low-level serial configuration?

I'm using embedded Linux platform, kernel is 2.6. I'm using stty command to configure ttyS* high level. The problem is that when I want to turn hardware flow control on: stty -F /dev/ttySA0 crtscts ...
4
votes
2answers
151 views

Why do newlines mess up my while condition?

I have a while loop that allows setting variables when written one way but does not allow it when written another way. Why is that? This prints var as 1234 and does not print var2 #!/bin/bash ...
2
votes
2answers
2k views

Displaying and updating a counter in bash

I think it's something like this: (Fedora14/bash) #!/bin/bash for i in {0..10..1}; do echo -e "$i"'\c' echo -e "\n\r" sleep 1 done But it doesn't work. Purpose: like this, but without the ...
-1
votes
1answer
957 views

Loop examples in bash [closed]

Any examples for "loop" in bash? for i in {1..5}; do echo $i; done 1 2 3 4 5 AND for i in 1 2 3 4 5; do echo "Welcome $i times"; done Welcome 1 times Welcome 2 times Welcome 3 times Welcome 4 ...
1
vote
3answers
1k views

Ls with spaces + variables

I want to do something like this, but it doesn't save the variable after the piping ends: fs=( ) echo ${fs[@]} ls -A1 | while read f do echo ${fs[@]} fs+=( "$f" ) echo ${fs[@]} done echo ...
-1
votes
3answers
507 views

calling functions within a function

I need to fetch the results of different time ranges and email the results, but i am having trouble with the email part of the script, how can i send an email with both results? (15min range and ...
7
votes
1answer
1k views

Most efficient way to run 2 while loops

Currently I use two different while loops to start my window manager, dwm, and the status bar that prints system info to it. My solution at the moment is to run them consecutively in the same script, ...
5
votes
2answers
6k views

loop curl get request bash

I'm trying to automate a curl script and eventually make it loop also. I found that I can't use any loop like: for i in `cat authors` do curl *line here* ...
20
votes
1answer
15k views

How to loop over the lines of a file?

Say I have this file: hello world hello world This program #!/bin/bash for i in $(cat $1); do echo "tester: $i" done outputs tester: hello tester: world tester: hello tester: world I'd ...