Programming :: Bash Background - & - With Control Operators -&&
Feb 11, 2009
I have a set of files to copy and decompress, and want to do these operations concurrently with a script.
Manually it would be something like:
Code:
The single & is intended to background the processes, while the && is intended to execute the gzip process if and only if the cp completes successfully.
My script is:
Code:
When I run it, bash gets angry with the following error:
Code:
So what is the proper syntax to accomplish this?
View 1 Replies
ADVERTISEMENT
Sep 3, 2010
What's the difference between using > and >>? How can I use both < and > (redirection operators) in a single command?
View 2 Replies
View Related
Apr 21, 2009
I'm trying to code the following WHILE loop in Bash:
While [string1 is non zero] and [string2 is non zero] and [counter < max]
Do
...
Done
I can't get the syntax right. I've tried:
Code:
while [ -n "$STRING1"] -a [ -n "$STRING2"] -a [$COUNTER -lt $MAX ]
But I get 'Too may arguments'
View 4 Replies
View Related
Apr 1, 2010
pretty simple. how would you background a process from a script and get its process id at the same time?
View 6 Replies
View Related
Aug 24, 2009
For example,I have three paragraphs,as following:
I want to output it as following:
View 2 Replies
View Related
Jul 3, 2009
I know of 4 different ways to use a for loop:
1. for I in {1..10}; do echo $I; done|
2. for I in 1 2 3 4 5 6 7 8 9 10; do echo $I; done|
3. for I in $(seq 1 10); do echo $I; done|
4. for ((I=1; I <= 10 ; I++)); do echo $I; done
I have a script which uses the 1st form of for loop. I'm trying to modify it to use a variable instead of a static hard-coded value in the section that controls the looping.of the for loop.
I've tried all different ways of quoting and escaping the variable, and the problem is that the quoting chars and escape char are being translated and passed into the loop along with the value stored in the variable.
For example, to change the start value of 1 to whatever value I want passed in through a variable:
Change:
I have tried: {{$a}..10} and {`$a`..10}, to have the variable evaluated first.
I have tried using the eval() function.
I have tried single and double quotes and the backslash escape character.
Nothing I've tried works. It's probably a syntax error.
View 14 Replies
View Related
Jun 7, 2011
So if you are a PHP-programmer (average one) and code for money, how many of funtions and operators of PHP should you remember by heart (in real life)? I was looking through php.net and man there are millions of tons of them!
View 9 Replies
View Related
Jan 20, 2011
The first is about implementing function calls. The way I currently have it is that functions are called with a C++ std::vector of nodes as the parameters. How would I turn a comma-seperated list of expressions into a C++ vector in the grammar?Second, how do you implement left-associative operators in a parser that does not allow left recursion?
And third, what would be the best internal representation of integers? A C++ int seems simplest, but limited. Using GMP seems more versatile, but I'm afraid it might seriously slow down the interpreter compared to C++ ints.
View 3 Replies
View Related
Aug 29, 2010
I have a basic script that watches my server, and informs me if it has gone down. I need to know how to run it without a console being open all of the time, I tried executing it with a trailing &, but to no avail.
Code:
for (( ; ; ))
do
if ping -b -c 1 chatify.net
then
[Code].....
View 3 Replies
View Related
Aug 28, 2011
Is it possible to change the GNOME desktop background during some period of time by just a random phrase from the list on black screen? Will is seriously load the CPU and consume battery life?
View 1 Replies
View Related
Jul 15, 2010
I created a system restore file.
code:
And hav tried out:
Code has been streaming past for ages. Longer than a fresh install!
I'm wondering if i've done something to create a cycle?
How and should i interupt it? If i ctl alt F7, will it take me back to Desktop?
View 6 Replies
View Related
Jul 11, 2011
I'm trying to get cron to run a bash script every 15 minutes to change my desktop background
running crontab -e I added
Code:
*/15 * * * * sh /home/ME/Documents/scripts/background.sh
(at first i didnt have the sh before the path of the script but read somewhere i needed that) But it doesnt seem to be running my script works fine if ran straight from the terminal so Dont think thats the problem.
View 9 Replies
View Related
Oct 19, 2010
I have tried a combination of the following lines in .bashrc to try and control duplicates in the bash history file:
export HISTCONTROL=ignoreboth
export HISTCONTROL=erasedups
export HISTCONTROL=ignoredups
[code]....
View 5 Replies
View Related
Sep 10, 2010
I had tried to control lynx by bash script. I can use bash script to let lynx open an url. After that, I can't do anymore. I don't understand how to move the cursor or fill some textbox in the webpage opened by linx in bash script.
View 3 Replies
View Related
Jul 25, 2010
Two processes are communicating through a pipe: A | B. A is writing data faster than B is reading it in. Is there any way to have A limit its writing rate to match B's reading rate?
AFAIK the pipe will get full, and will make A's writing block, waiting for B to read in more data. But is there a way to limit A's writing rate before the pipe fills up? (In a way it's like having a pipe with a really small capacity, but as far as I know pipe capacity is a constant compiled into the kernel.)
Code:
EXAMPLE FOR CLARIFICATION
Right now the command is printing out the following in 1-second intervals:
But with flow control it should print out (again in 1-second intervals):
...since "date" would block on the writing loop due to the slow reading loop.
View 4 Replies
View Related
Mar 18, 2011
I'm making an bash script.
As input you can input different numbers from 1 to 3.
Depending from the input a text shows up.
View 2 Replies
View Related
Aug 20, 2009
I want to set a key binding in bash for "history-search-backward" readline command to a combination of Control+some other key (I'm using 2 as an example), but I'm unable to do so. in fact, I'm unable to alter or add bindings to Control+key combinations.
After several tries my ~/.inputrc now looks like this
But it doesn't work and bind -p | grep "-2" gives nothing. If I try something without the control key:
I can search in the history by prssing the sequence C + - + 2.
bind -p gives control in C form, for example:
I've tried different formats in my inputrc:
But nothing works.
works if I press Escape followed by 2.
Setup:
Fedora 11:
Bash version 4.0.23(1)
GNU Readline 5.2 (according to the man page)
View 2 Replies
View Related
Nov 14, 2010
How do i do to:1. Check if there is a audio source plugged in via line in?2. Control the volumeI want to do it through either bash or python script.
View 1 Replies
View Related
Feb 4, 2011
I would like to know how do I print the line # in a script. My requirement is, I have a script which is about ~5000 lines long. If there are any errors happen I just exit. And I would like to add the line # of the script where the error happened.
View 3 Replies
View Related
Jan 24, 2010
simple bash code:
Code:
#!/bin/bash
trap "echo 'you got me'" SIGINT SIGTERM # to trap ctrl+c
echo "Press ctrl+c during 5 sec loop"
for ((i=0;i<5;i++)); do
[Code]...
How come code behaves normally and stops when ctrl+c signal is caught and resumes, but after I use at least one timeout read in the code it looks like, if signal is caught again it doesn't pause the execution but skips the loop. If you remove -t (timeout) option from the read, both loops look the same!
View 10 Replies
View Related
Nov 23, 2010
I am starting an instance of mplayer from a bash script, opening an audio stream:
Code:
mplayer [URL]
How do I do to control this mplayer instance from another script? I want to control volume and pause it from within the bash script. I know the commands for doing so from terminal, but once mplayer gets started from the script, how do I 'direct' the commands to that specific mplayer instance?
View 9 Replies
View Related
Nov 26, 2008
I have a config file that contains:
my.config:
Code:
Now in my bash script, I want to get the output /home/user instead of $HOME once read. So far, I have managed to get the $HOME variable but I can't get it to echo the variable. All I get is the output $HOME.
Here is my parse_cmd script:
Code:
View 3 Replies
View Related
Jul 25, 2011
I have written quite a few separate bash & scripts and php scripts that up to now I have run from cron jobs. However I have to estimate how long each takes to run, before running the next and so it probably takes much longer than necessary to run them all. They have to run in order.
Now there are so many I am thinking it would be better to have a master bash script that would run one after the other, but I am not sure how to get the master script to wait before starting to run the next script. Is this possible and is there a command that will make the script wait between bash and php scripts , for them to finish, before running the next?
View 5 Replies
View Related
Sep 5, 2009
I was wondering about the differences between "$PWD" '$PWD' `$PWD`. Basically I just don't understand exactly how '' "" `` change the output of the command.
View 1 Replies
View Related
Dec 14, 2009
How can I implement logical operators in grep? I checked the man info and couldn't figure it out. For example, I'd like to display lines in file1.txt that contains word1 OR word2.
cat file1.txt | grep word1 OR word2
View 3 Replies
View Related
Jan 9, 2010
I would like to get the filename (without extension) and the extension separately. The best solution I found so far is:
Let FILE="thefilenameofsomefilesfor_instance.txt"
Code:
NAME=`echo "$FILE" | cut -d'.' -f1`
EXTENSION=`echo "$FILE" | cut -d'.' -f2`
I think it would be better to count the len and remove 3 chars to right to get the extension, but it can be macintosh filenames with have 4 chars for extensions.
View 5 Replies
View Related
Dec 26, 2010
I'm trying to write a small application controlling spotify, running under wine, that I can run from my desktop computer and use via SSH on my mobile phone, and so far I've been quite successful. At least until just recently, when I tried to use the read command to read a single key-press on my phone, and use that input instead of having to type the number for item in the menu I've created. I tried to simply use the read command to silently listen to one key-press and output it to the variable opt. To do this I tried:
read -s -n1 opt
When I ran this in a shell-script this I got:
read: 1: Illegal option -s
Seeing this, I tried to remove the -s operator, which left me with:
read: 1: Illegal option -n
I decided to remove all operators and echo the variable opt, leaving me with:
read opt
echo "$opt"
Which worked as expected. It echoed the key that I had pressed. I moved over to my terminal window and tried the read command from there, and it did exactly what it should. It silently recorded one key-press to the variable opt.
why isn't read working with operators in shell scripts?
View 2 Replies
View Related
Mar 26, 2010
I wrote a spinner in Perl and when I did a spinner in shell I could just run the subroutine in the background.
[code]...
In Perl, how do you run a function in a background and get the PID for that? I know PID in Perl is $$
View 2 Replies
View Related
Mar 10, 2010
I think my title pretty much explains it. I am writing a script and I want to start a program in the background, and when that program finishes I want to check the return value to make sure there was no error.For example normal I would do something like this:
#!/bin/sh
program
if [ ! $? -eq 0 ]; then
echo "There was an error"
exit 1
fi
Now I want to do something like this:
#!/bin/sh
PRTN=`program1 &`
program2
if [ ! $? -eq 0 ]; then
[code]....
In this case if program2 finishes before program1, I don't think the return value from program1 $PRTN would be valid at the time it is checked.
View 3 Replies
View Related
Apr 6, 2010
I have some ideas about writing a small game in terminal ( just for fun ) using ncurses library. I want to use some kind of menus (in Midnight Commander's style), but there are some problems with rendering windows, that I don't understand. I create a window with newwin(), assign a color pair to it calling wattron() (for example, I want to fill a window with blue background), and then I call my own function wnd_fill() :
Code: void wnd_fill (WINDOW* wnd)
{
int i;
[code]...
View 9 Replies
View Related