bash

How does one output bold text in BASH?

I'm writing a bash script that prints some text to the screen: echo "Some Text" Can I format the text? I would like to make it bold. Thank you. ...

How to create a CPU spike with a bash command

I want to create a near 100% load on a Linux machine. It's quad core system and I want all cores going full speed. Ideally, the CPU load would last a designated amount of time and then stop. I'm hoping there's some trick in bash. I'm thinking some sort of infinite loop. ...

How to perform an action when a remote (Http) file changed?

Hi, I want to create a script that checks an URL and perform an action (download + unzip) when the "Last-Modified" header of the remote file changed. I thought about fetching the header with curl but then I have to store it somewhere for each file and perform a date comparison. Does anyone have a different idea using (mostly) standar...

" mv * dir " doesn't work in a script?

I want to move all the files to a new dir. From the command line I can do "mv . newdir" but if I try with this script: #!/bin/bash -f # mkdir newdir mv *.* newdir I get the following message: mv: rename *.* to newdir/*.*: No such file or directory ...

Regexp in bash for number between "quotes"

Input: hello world "22" bye world I need a regex that will work in bash that can get me the numbers between the quotes. The regex should match 22. Thanks! ...

echo -e acts differently when run in a script by root on ubuntu

When running a bash script on ubuntu 9.10, I get different behavior from bash echo's "-e" option depending on whether or not I'm running as root. Consider this script: $ cat echo-test if [ "`whoami`" = "root" ]; then echo "Running as root" fi echo Testing /bin/echo -e /bin/echo -e "foo\nbar" echo Testing bash echo -e echo -e "foo\nb...

bash testing a group of directories for existence

Have documents stored in a file system which includes "daily" directories, e.g. 20050610. In a bash script I want to list the files in a months worth of these directories. So I'm running a find command find <path>/200506* -type f >> jun2005.lst. Would like to check that this set of directories is not a null set before executing the find ...

Escape characters contained by bash variable in regex pattern

In my bash script, i am trying to execute following Linux command: sed -i "/$data_line/ d" $data_dir $data_line is entered by user and it may conatain special characters that could brake regex. How can i escape all of the possible special characters in $data_line before i execute sed command? ...

How do I play with test command properly?

[root@jiaoyou ~]# test 1 = 1 -a 0 = 1 [root@jiaoyou ~]# if [1 = 1 -a 0 = 1]then echo 1;else echo 2;fi -bash: syntax error near unexpected token `else' Why test doesn't give any output and the if statement fails? Can someone point out what's wrong here? UPDATE Can someone illustrate how to simulate complex expressions like 1=1 and (0...

Why 0 is true but false is 1 in bash?

false; echo $? The above will output 1,which is contradictory with all other programming languages I know. Any reason in this? ...

Bash: infinite sleep

I use startx to start X which will evaluate my .xinitrc. In my .xinitrc I start my window manager using /usr/bin/mywm. Now, if I kill my WM (in order to f.e. test some other WM), X will terminate too because the .xinitrc script reached EOF. So I added this at the end of my .xinitrc: while true; do sleep 10000; done This way X won't te...

Bash scripting know the result of a command.

Hi, I am writing a bash script to run an integration test of a tool I am writing. Basically I run the application with a set of inputs and compare the results with expected values using the diff command line tool. It's working, but I would like to enhance it by knowing the result of the diff command and print "SUCCESS" or "FAIL" depen...

POSIX SH build loop variable with elements containing spaces

Here's the code I need: #!/bin/sh x1="a1 a2" x2="b1 b2" list=SOMETHING for x in "$list" do echo $x done And the output I want: a1 a2 b1 b2 The question is: what should SOMETHING be? I want $list to behave just as $@ does. Notes: I can't use $IFS and I can't eval the entire loop. ...

How to set a default value in an IF snippet?

Hello, I have the following snippet in a bash script written in Solaris 10: printf "port(389)=" read PORT if [[ $PORT == "" ]]; then PORT=389 fi What I am trying to get that if the user hits the enter key, the Port should be set to 389. The snippet above does not seem to be working. Any suggestions? ...

Test whether a glob has any matches in bash

If I want to check for the existance of a single file, I can test for it using test -e filename or [ -e filename ]. Supposing I have a glob and I want to know whether any files exist whose names match the glob. The glob can match 0 files (in which case I need to do nothing), or it can match 1 or more files (in which case I need to do so...

cURL: from PHP to BASH

Hi.. I've never done any curl before so am in need of some help. php: <?php $ch = curl_init(); $data = array( 'uptype'=>'file', 'file'=>'@'.$argv[1], ); curl_setopt($ch, CURLOPT_URL, 'http://my_site_ex/up.php'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_exec($ch); curl_clo...

How do I get Git's latest stable release version number?

I'm writing a git-install.sh script: http://gist.github.com/419201 To get Git's latest stable release version number, I do: LSR_NUM=$(curl -silent http://git-scm.com/ | sed -n '/id="ver"/ s/.*v\([0-9].*\)<.*/\1/p') 2 Questions: Refactor my code: Is there a better way programmatically to do this? This works now, but it's brittle: if...

how to read rows?

I'm trying to read first row from the file > source ./rank file using this script set line = ($<) <- inside rank but when I enter echo $line I receive nothing, how can I change it? thanks in advance ...

Question about regex in linux commands.

I ran the following command at linux bash: apt-cache search hex.*(view|edit) My intention was to find any software packages whose name/description contains the pattern 'hex.*(view|edit)'. But among the results I got this: kipi-plugins - image manipulation/handling plugins for KIPI aware programs How could this be in the results lis...

logins with cURL

I'm looking to use cURL to login to Blackboard, a course management system used a many universities. (For example, http://blackboard.unh.edu) How would I do this? Blackboard uses HTTPS certificates and cookies too I believe. Thanks! ...