General :: Case Statements In Bash Scripts

Sep 4, 2010

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)

View 4 Replies


ADVERTISEMENT

General :: Bash Scripts - Comparing Multiple Items Or Conditions Using 'if' Statements?

Mar 12, 2011

comparing multiple items or conditions using 'if' statements? I want to do something if one or more conditions is true, for example:

If a = 1 or b = 1.

I've tried:

[Code]...

View 5 Replies View Related

General :: Change Case Of A String (BASH Scripting)?

Jul 9, 2010

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 Related

General :: Exit Bash Script - Add - Del - Edit User From Certain File Using Different CASE Variables

Mar 6, 2010

I 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.

View 6 Replies View Related

Programming :: BASH - Regex In A Case Statement?

Jun 9, 2010

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]...

View 3 Replies View Related

Programming :: Escape '*' In Case Statement Bash

Jan 23, 2010

Does it possible to escape * in the case statement

Code:

View 2 Replies View Related

General :: Shell Script Statements In Init?

May 21, 2010

I have made some modifications to the init script that runs when my PC boots to take me to a /bin/sh shell so I can run some custom scripts. When I exit from here the init statement should mount the root file system and switch_root to it. This all works correctly however the same init statement will be run on two types of pc's and the address of the root fs is different between them. On one PC it sits on /dev/sda1 and on the other /dev/hda1. To select the appropriate addresses I used dmesg to find out if it was the i5 PC and if/else statements to select the right hard drive location.

When I try use a if/else statement in the init script it ends up preforming both the if and the else code. Is there any reason the if else statements wouldn't work the exact same in the init script (it's all shell scripts isn't it?

[Code]...

View 3 Replies View Related

General :: Looping Through A Shell Script With Sql Statements?

Oct 7, 2009

I'm working on the Solaris environment and the DB i'm using is Oracle 10g. Skeleton of what I'm attempting; Write a ksh script to perform the following. I have no idea how to include my sql query within a shell script and loop through the statements. Have therefore given a jist of what I'm attempting, below.

1. Copy file to be processed (one file at a time, from a list of 10 files in the folder ).

Code:

for i in *
do
cp $i /home/temp

2 . Create a snapshot(n) table : Initialize n = 1

Code:

create table test insert account_no, balance from records_all; -- creates my snapshot table and inserts records in SQL

3. Checking if the table has been created successfully:

Code:

select count(*) from snapshot1 -- query out the number of records in the table -- always fixed, say at 400000

Code:

if( select count(*) from snapshot(n) = 400000 )
echo " table creation successful.. proceed to the next step "
else
echo " problem creating table, exiting the script .. "

4. If table creation is successful,

Code:

echo " select max(value) from results_all " -- printing the max value to console

[code]....

View 7 Replies View Related

Slackware :: Mkisofs -iso-level 1 Converts To Lower Case Instead Of Upper Case?

Oct 28, 2010

Kernel 2.6, Slackware 12.0
mkisofs 2.01

I do 'mkisofs -iso-level 1 -o image John Smith.txt'. Only an example. When I mount image, ls outputs john_smi.txt. So it has shorten to 8.3 and translated ' ' into '_'. This is in accordance with the manual, although it doesn't say the conversion will be done.

Quote:

-iso-level level
.........................
With all iso9660 levels from 1..3, all filenames are restricted to upper case letters, numbers and the underscore (_).
...........................

However, as it did not reject the file name, it should have converted it to all upper case, it seems to me. And -iso-level 2|3 does the same thing.

Code:

root@darkstar:~# mkisofs -iso-level 1 -o image John Smith.txt
Total translation table size: 0
Total rockridge attributes bytes: 0
Total directory bytes: 0

[code]....

View 5 Replies View Related

Ubuntu :: Error - Set A Valid User Name Consisting Of A Lower Case Letter Followed By Lower Case Letters And Numbers

Mar 12, 2010

I tried to add my wife , and when I put in a password for her, this error comes up."Please set a valid user name consisting of a lower case letter followed by lower case letters and numbers." I did all that and I still can't set a password for her.

View 3 Replies View Related

Programming :: Perl Switch Statement Throwing Error Like Bad Case Statement (invalid Case Value)?

Oct 6, 2010

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]...

View 3 Replies View Related

Ubuntu :: Using Variables In Awk IF Statements?

Nov 2, 2010

I have a list of names (testnames.txt) and I have a set of log files (testlogdata.log). I'm trying to search the column in my log file for each of the names in my testnames.txt file, and output the result to individual files, name1.txt, name2.txt, name3.txt, etc the names in the column of my log file can appear in different formats , ie the name "Tom Smith" can appear as "tom_smith", "tom-smith", "ACME/tom.smith", "ACME/thomas.smith". etc. To allow for the variations, I have my names in the testnames.txt as expressions, ie, for tom smith, I use the expression "to.*smith", etc.I'm running the following command:

for i in $(cat testnames.txt); do awk '{if ($9~/$i/) print $0}' testlogdata.log > $ioutput.log; done

I want the command to read a value for i, insert it into the if ($9~/inserted value for i/, and dump each line from testlogdata.log into a file named <value-for-i>output.log.

View 4 Replies View Related

Ubuntu :: Script Driving Nuts With If Statements?

Oct 21, 2010

I for the life of me is having a hard time with some scripting in Dash with branching statements. What the heck? I read many tutorials all over the net and none of the codes work. They suggest all sorts of variations, but it ain't working for me. Can anyone tell me why the code below always return "Y"?

Code:
#!/bin/sh
clear
echo -n "---> Enter Y or N? "
read answer
if [ "$answer"="Y" ] ; then

[Code]...

Perhaps someone can give me a short explanation on how if statements work? So far my linux experience has been nothing, but a frustrating mess.

View 4 Replies View Related

Programming :: Cannot Get Conditional Statements To Work In XDialog/Dialog

Feb 5, 2011

I cannot seem to get if else statements to work. if $choice == Dog then i want it to say "you selected Dog" The variable choice has the value Dog in it as proved at the end by echo "yes $choice is $choice" following the error Code: ./test.sh: 37: [$choice: not found How do i get the conditional statement to work? What's wrong here? This is the full script:

Code:

#! /bin/sh
: ${DIALOG=dialog}
: ${DIALOG_OK=0}

[code]....

View 7 Replies View Related

Programming :: If Statements With Decimal Places - Compare It To A Predefined Value

Aug 11, 2010

I'm writing an if statement where a variable is a number such as 14.05 (this is actually a temperature) and I want to compare it to a predefined value, sample code below:

Code:

I have all sorts of errors regardless of how I do this (double quotes, square brackets). The best idea I've had is stripping off the decimal place so it's a 4 digit number (e.g warning=1503 and DEV_TMP=1405) however this seems a little unnescessary and I'm sure there's an easier way of achieving the same thing.

View 11 Replies View Related

General :: One Drive Bay PC Case?

Sep 17, 2010

I know this is a rather odd question, but like in the old days you can get one drive bay desktop cases.

View 4 Replies View Related

Programming :: SQLite Read, Write, Select, Compare Statements For C++

Jun 9, 2010

I am using C++ with SQLite db in a program that will read read a sub set of records, compare records and write different records to another database. I have a SQLite book, but it only shows examples for the C API. Anyone have code samples in C++ for the following:

Open database
Close
Select *
Read
Write

Or, just show me how to execute a SQL statement with C++ and I can then figure out the various SQL statements I need.

View 5 Replies View Related

General :: GNU Sort By Case-sensitive?

Aug 20, 2010

The sort utility in Ubuntu 10.04 (Lucid) always sort by case-insensitive, just like if you specify --ignore-case to it. The two sort just give the same result:

[Code]....

But sometimes I want to sort by case-sensitive, so the upper-case letters come first, then lower-case letter.

View 2 Replies View Related

General :: Case Sensitive Directory

Dec 14, 2010

i am trying to set up a couple of pages in some special directories URL...but i need it that if they type URL... for them also to go to the site and not to a 404

View 2 Replies View Related

General :: Turn Off Terminal Case Sensitivity?

Sep 19, 2010

As above can I turn Case Sensitivity off for terminal in linux?

View 3 Replies View Related

General :: Browser Should Try Again In Case Of 'can't Find Server'

Apr 27, 2011

When my internet is slow & i try to open a web page then I get message in my firefox 3.6.3 that 'can't find server at www.website.com'. It isn't that URL is wrong but maybe connection to DNS server is slow or something similiar. I remember that wget tries 20 times by default to get the file (browsing is downloading+ decoding+ displaying).Does any web browser or addon tries repeatedly till it is successful in contacting website server? It can tell me 'trying nth attempt at www.website.com'

View 2 Replies View Related

General :: Check If Filenames Are Lowers Case?

Feb 5, 2010

What would be the best way to verify files in a folder are all lower case and if a file is not lower case, output the filename to the screen.

View 11 Replies View Related

General :: Disable Case Sensitivity For Slackware?

Feb 19, 2010

How you disable it? it makes no sense you have to type all those non capital and capital letters just to access a directory correctly.

in windows you just type the name and it detects whatever you type capital or not...

View 3 Replies View Related

General :: Case Statement In Shel Programing?

Mar 15, 2010

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]....

View 2 Replies View Related

General :: Only Case Sensitive Is Available To Mark/unselect?

Jun 28, 2010

my ubuntu 8.04 is GNOME based.I am using kpdf 0.5.10 (using kde 3.5.10)

In find dialog box > options
only case sensitive is available to mark/unselect while
find backwards ,

[code]....

View 5 Replies View Related

General :: Vim: Setting Case Insensibility In Searches?

Jul 27, 2010

Linux kernel 2.6, Slackware 12.0

How do I set case insensibility in searches running vim? I thought I could find this in the manual or the in browsing help within the program itself, but it was not long before I realized I was mistaken.

View 5 Replies View Related

General :: Windows - Make Rsync Case Insensitive

Mar 12, 2011

I'm rsync'ing a bunch of files between a Windows and a Linux system. Since not all Windows care about case, some of the files on the Windows system no longer have the same casing as they had on the Linux system. But rsync now treats these files as different and uploads a new copy.

Is it possible to have rsync ignore the case?

View 3 Replies View Related

General :: Case Insensitive Search From Find Command?

Apr 29, 2011

I am not able to figure out how can I do case-insensitive search using the find command.

I tried

find . -name -i pattern

And it does not work.

View 2 Replies View Related

General :: Case Insensibility In Filenames And Rsync, Mount?

Nov 27, 2010

Is there a way of making rsync (an offspring of rcp) case insensitive? Perhaps mounting the file system (not linux) in some special way?

View 14 Replies View Related

General :: Ignore Case Only For Part Of Regular Expression

Feb 15, 2010

What I want to achieve is, if I have following in my file:
x y
X z
I should be able to find the pair, x Y and replace it with x a. So, basically I want to search for case sensitive 'x' but search and replace case insensitive 'y'. How should I do it? Can this be achieved with 'sed' command?

View 8 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved