Programming :: Escape '*' In Case Statement Bash
Jan 23, 2010Does it possible to escape * in the case statement
Code:
Does it possible to escape * in the case statement
Code:
I've written a simple perl code to learn switches in perl.My code is pasted below,
#!/usr/bin/perl
$opt = 1;
switch($opt) {
[code]...
the following works and BASH doesn't complain, but VIM highlights the closing square bracket is if it sees a syntax error. Is there a better way to express regex in a case statement or is this an issue with VIM?
Code:
#!/bin/bash
case $1 in
[code]...
I've started dabbling with the case statement in order to pass some option's arguments into variables. I do not think I am doing this right.
Code:
usage() {
echo "Usage: $0 [-z|--snooze] [-c|--channel] [-p|--playlist]
[-m|--message] [-v|--mpcvolume]"
[code]....
As you can see, I want to pass arguments depending on the option(s) chosen by the user; ie. --snooze, or --channel. By default, if no options are chosen, I'll display a usage message; though in the future I'll provide some sane defaults. I'd like to create a case statement to handle passing arguments to any number of options; something like:
Code:
wakethehellup.sh --snooze 20 --message 'wake up!'
and for the other arguments, it would have a default set. The case statement I provided fails with a syntax error "syntax error near unexpected token `$2'" near the '--snooze' in the statement, so I take it you can't pass a parameter in this way; but I'm confused as to how I'm supposed to pass different parameters to different options without the options being confused as parameters.
How do i make my strings case-insensitive while comparing them with an if statement?
View 2 Replies View RelatedWhen you use an if statement directly in bash you have to put the ";" at the end or not? or am I mixing it with the for loop? I am reading advance bash scripting and it shows the if - then statements without ";" so I need a little clarification here.
View 2 Replies View RelatedThe script that Iam trying to write is running a for loop and reading line by line from a text file. inside this for loop i would like to execute update SQL statement .
a pesudo code is
Quote:
`$ISQL -U $username -P $Password -D $Dbname -I $INTERFACE <<QRY
for id in $idlist #idlist iam reading from a file
[code]...
This script that I found online does the job it promises. it does convert the files to mp3 without an issue. What I need to include now is an if statement that says If $file.mp3 exists then delete $file.wav
Code:
#!/bin/sh
# name of this script: wav2mp3.sh
# wav to mp3
# Credit to the script creator (Nikesh Jauhari):
[Code]...
After that I'm stumped as to how to do the if statement
I wrote the Automatik widget (you can find it at :http://kde-look.org/content/show.php...&PHPSESSID=caeTo improve it, I would like to add this one-line script into a text sensor :
top -b -n 1 | head -12 | tail -6 | sed '/top/d' | awk '{ printf "%-12.12s %-4s %-4s %-3s
" , $12,$9,$10,$2}'
[code]...
I need a script that can print some series of strings in colors based in the information of a file, for simplicity let's say it only does:
Code:
#!/bin/bash
printf "e[1;31;32m%-10se[00m" "OK"
When you execute this in the command line it prints a bold green 'OK'. So far so good.
Now, I need to check the output of the script over time using the command watch. The problem then arises. watch seems to ignore the escape codes and just prints:
Code:
[1;31;32mOK [00m
Is there any way to fix this?
If not, how can I check inside the script if it is being executed from a command? (watch in this case) So I can print without color for those cases.
I am trying to use sed command to repalce one string with other but somehow replacement string contains forwards slash hence getting the error statement garbled!
[Code]...
At the moment I got my md5sum checking working which I write to a text file and see below.
If the md5sum works it will write the output to check2.md5 test.txt: OK
If the md5sum fails it will write test.txt: FAILED
How do I write if statement to check the output whether or not the md5sum failed or not ?
check1="/home/ops/Desktop/test1/check1.md5"
check2="/home/ops/Desktop/test1/check2.md5"
cd /home/ops/Desktop/test1
md5sum test.txt > $check1
[Code]....
I am facing problem with the following script. Could you please look into this.echo 'Enter Staging number' case $STGNUM in
1)
for i in {'stg1-greg','stg1-marsha','stg1-peter','stg1-jan','stg2-greg','stg2-marsha','stg2-peter','stg2-jan'};do echo $i; ssh $i sudo -u dev /opt/usr/apps/workflow/stopwf.sh;done;
[code]....
We are building our C++ project in Kdevelop IDE. Every time we run "Run Configure" from the "Build" menu, a file named "libtool" gets automatically generated. This file contains a statement as "ECHO="echo"".f we run "Automake", without modifying the "libtool" the system hangs and theputer needs to be restarted.Therefore every time we run "Run Configure" we need to include the line "echo="echo"" below the statement "ECHO="echo"" manually.I think a script can be written which does the above on its own.I am not a shell script programmer, I know the good tutorials for shell scripts are available on the net, but learning scripting only for this task would be time-consuming and painful.
View 4 Replies View RelatedHere's my need:
If Calendar Day= Then FCPeriod= And FCYear=
Jan 11 to Feb 1002Current Year of Feb 10
Feb 11 to Mar 1003Current Year of Mar 10
Mar 11 to Apr 1004Current Year of Apr 10
Apr 11 to May 1005Current Year of May 10
May 11 to June 1006Current Year of June 10
June 11 to July 1007Current Year of July 10
July 11 to Aug 1008Current Year of Aug 10
Aug 11 to Sept 1009Current Year of Sept 10
Sept 11 to Oct 1010Current Year of Oct 10
Oct 11 to Nov 1011Current Year of Nov 10
Nov 11 to Dec 1012Current Year of Dec 10
Dec 11 to Jan 1001* Current Year of Jan 10
* Note for Dec 11 - Dec 31,
The Next Year to be used
IE: Current date is Dec 28th, 2010. Year = 2011
IE: Current date is Jan 8th, 2011, Year = 2011.
Looks like I'll need a case statement with some regular expressions...
Im a bit stuck with a simple script that im practicing with... im trying to get my head around some simple scripting. Basically i want to write a script that will work as below: It will ask the user to enter their userid. If its correct it will say 'Correct' If its the wrong id (But the ID exists in /etc/passwd) then it will say 'incorrect' If its not a valid userid it will say 'doesnt exist'. What i have so far is:
[Code]...
# If the user enters their own userid they will get a comment saying 'correct' $LOGNAME) echo "Correct";;
# If they enter another users ID (That exists in the /etc/passwd), then they get a message to say 'incorrect userid used'. Im not sure what i need to do here to get it to check the /etc/passwd to see if the input exists in there.... im guessing some kind of simple 'if' statement to say ---- "if 'input' exists in /etc/passwd then echo "incorrect userid used"
# If its entered incorrectly and not a valid ID then they will get this comment. Again, im guessing this part would be similar to te above option..... *) echo "not a valid ID";;
Ive managed to work out how the basic Case staements work, but to add a conditional statement based on the input, i just cant figure out. I have tried looking on google, and found some help but it doesnt really explain how i check the input against the /etc/passwd.
For some reason, I get said block of errors when I run my script without arguments:
Code:
/home/mark/bin/backup: line 34: [: =: unary operator expected
/home/mark/bin/backup: line 37: [: =: unary operator expected
[code].....
I want to have the System Bell ring when a process is over say a download. First I created a file named 'beep' that plays the System Bell. Because the System Bell rings by hitting cntrl-G the 'beep' file looks like this.
Code:
echo ^G
I then give the file owner execute permission. I know that this command would serve my purpose.
Code:
[URL]
However I want to sharpen my Bash programming skills. I wanted to write the Bash script along the following logic and with the fewest lines possible. Not really a script, I want to insert this short script via command line instead of a file. Let's say the download has commenced and the PID = 16666.
Code:
until ps -p 16666
do
/root/beep
done
Now obviously 'ps -p 16666' will already evaluate to true. My question is, is there a way to maybe enclose 'ps -p 16666' and prepend some operator that inverts the condition to where until 'ps -p 16666' evaluates to false then run /root/beep?
I need to to write a bash script using an If...Then...Else statement that will accept a day of the week from the command line what do I do or where do I go.
View 2 Replies View RelatedI know with if statements in bash you can do
Code:
if [ $fruit = apple ]
then echo "Good, I like Apples"
fi
But I was wondering if you could do something like this:
Code:
if [apt-cache pkgnames smbfs = smbfs doesn't exist]
the apt-get install smbfs
fi
If so how would you capture the output from apt-cache pkgname smbfs to determine if it's installed?
Here's the bash script:
Code:
FILES="/usr/sbin/accept
/usr/sbin/pwck
/usr/sbin/chroot
/usr/bin/fakefile
[code]....
Notice the extra" file size" lines in there? What's causing that? I'm trying to learn more bash skills. I have no experience with awk because I have been unable to understand it's basic necessity. But I thought maybe if I try it with some test scripts I might become more interested in using it more and expand my very limited capabilities.
while learning to write bash scripts, i decided to write some script that, given an integer as input, will tell you the square root of that integer (provided the integer in question is a perfect square). i have already done on using primarily if statements and a while loop. i decided that using a case statement would be a lot simpler and i would be able to make the script more functional. here is what i have so far
[Code]....
i have tried all posible combos of using -ge or >= but i get pretty much the same thing.
the idea is, for now, if the input is greater than or equal to 0 that it will echo test. can you do this sort of thing with case statements? or will it only work if i give it specific values like [1-9] (if this is the case then i dont think the case statement will work for what i want to do)
Is there any inbuilt functionality in Unix shell script so that i can able to convert lower case string input to an upper case? I dont want to use high level languages like java,python or perl for doing the job.
View 4 Replies View RelatedI have made a simple bash script through which i can add, del, edit user from certain file using different CASE variables. like
case
1. adduser
2. del user
3. edit user
Now i want to add a exit CASE like
1. adduser
2. del user
3. edit user
4. exit
Now i want to make a script such a way that, if user input is 4 then only script quit. I used with exit function also but it didn't work. if user press ENTER or other keys then also it quit the program.
My goal is to send escape characters from Linux to make scanner's LED blink. I've started with a simple "beep" command:
echo -e "�7"
and it worked. We are using WaveLink emulator and the escape sequences for the LED are
echo -e "�33%150;200;5L"
Linux returns me this: 150;200;5L
So, it doesn't work. What am I doing wrong for the LED sequences?
I want to read a input from user and output something like 'inputcd', which has to escape all backslashes if using double-quote. For instance, the following code would work.
Just curious if any other way I could do it without specify all backslashes? Since that takes much efforts when the sequence is long.
Code:
I am trying to create a script to be used on RHEL server. If I replace the $t with a number, the script works. If I try add a variable or the $1, the script doesn?t work (returns all processes even if less than the $t value). I thought that it may be treating it as a literal, but I wasn?t sure of the conversion.
t=$1
echo $t
lcnt=`ps -eo pid,ppid,rss,vsize,pcpu,pmem,cmd -ww --sort=pid | awk '{if ($6 > $t) print
[code]...
I have a site which will have, for example, a login system where people have to enter their usernames and passwords, depending on which they'll be let in to the site. So, in code, I've got a line like:
if ($_POST['password'] == $password) {
then do whatever
}
else { print "Wrong password" ; )
My problem is, this "Wrong password" printing is just a solitary line, not keeping with the colours and style of the site, and it looks very bad. I want to ideally, output some HTML, which will have a picture, and print the "Wrong password" in the font and colours I desire. Do I have to put all the HTML in a print statement, and then deal with the nightmare of escaping all the quote marks in it with a ""? Or is there a cleaner method to the whole thing? Maybe something like this -
if ($_POST['password'] == $password) {
then do whatever
}
[code]....
I'm trying to code a sql statement for use in a PHP script.I'm looking to find the number of matching records in two tables and display them.How would you write that statement.I've tried using count a few ways, but no cigar.
View 2 Replies View RelatedOk, so I find myself ripping audio CDs frequently, which I then lame to mp3's to put on my media player. I usually define the --ta and --tl (artist and album) ID3 tags and batch encode each album, but don't bother with the track tags as I'd have to do each one seperately.
So, I'm working on a script to do all this for me, extracting info from 'pwd' etc. to fill in the blanks for --ta, --tl and --tt (track name). All is working well, except that I can't get sed to pass on the "" character to lame to escape spaces.
Here's what I've got so far: (trouble spot is bolded - no need to pay attention to the rest of it)
Code:
All this does is pass a 'space' on to lame, which it takes as an invalid argument.