Programming :: Shell: Give A Range Argument To 'for'

Feb 20, 2010

Feel free to just link to another thread where this is (pre)solved; I can't search the forum for the word "for," because it's too short (or maybe the search engine dislikes prepositions).

Is there a way to give the 'for' command a range? Here's what I mean:

Code:
#for i in (1-5); do echo $i; done
Certainly, meat space user; I understand exactly what you're thinking.
1
2
3
4
5
True, I realize I could use

Code:
COUNT=1 ; while [ $COUNT -lt 6 ]...

...but if I can avoid the extra preparatory step I'd prefer to do so.

View 2 Replies


ADVERTISEMENT

Programming :: Shell Scripting - Value Disappears Depending On Argument Order

Mar 21, 2011

Examples:
Code:
$ ./test.sh -a -c 2
operator is -gt
remcount is
^ value missing!

Code:
$ ./test.sh -b -c 2
operator is -lt
remcount is
^ value missing!

Yet when "-c" is the first argument, its value is present:
Code:
$ ./test.sh -c 2 -b
operator is -lt
remcount is 2
What could I do to ensure the value of "-c" is picked up regardless of the argument order?

View 5 Replies View Related

Programming :: Bash Shell Read User Argument From Command Line And Test It

Aug 29, 2010

Trying to create a small script that will read user's input, test if user entered some input and if not display some message or display a text using user's input.

The script is the following but i get an error saying "[: 6: =: argument expected"

View 12 Replies View Related

Programming :: Bash Script To Ping A Range Or Own IP-range?

Apr 11, 2011

I want to build a bash script, which can ping a range IP adresses which will be filled in by the admin. If there is no IP-adress filled in, then the script must ping the subnet where the system is logged on. So if my ip is 192.168.1.6, then the script must ping from 192.168.1.1 till 192.168.1.255 Or else, if there is given a beginning and ending ip it must ping that!

The first part of the bash script is to ping a given range (see below). But there is one problem, how can I tell the script to ping from $begin till $end, [..] is of course wrong! But what must be filled in there???

echo "Enter beginning IP-adres:"
read begin
echo "Enter ending IP-adres:"
read end
ping -c 1 $begin [..] $end

The second part is to find my own ip and ping the whole range.. How to do that? I only can find my own IP, but I cant ping the whole range,, how to do that?

#!/bin/bash
ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' |
cut -d: -f2 | awk '{ print $1 }'

View 11 Replies View Related

CentOS 5 :: Pass Shell As Command Line Argument When I Ssh To An Account

Jan 25, 2011

I want to have a choice or more preferable pass shell as command line argument when I ssh to an linux account.i.e. If John logs in to account "zzz" on server "abc", by default definition of account "zzz" n server "abc" he get csh.But Sally desires that when she logs in to account "zzz" on server "abc", she needs the login shell to be ksh,and Rick wants bash when he logs in to account "zzz" on server "abc".What is the most non-intrusive / easiest way to achieve this? Each user can set their preference on ssh command line or create a simple alias by each shell, but not sure how to do this.

View 6 Replies View Related

General :: How To Get Bash Shell History Range

Oct 4, 2010

How can I get/filter history entries in a specific range?I have a large history file and frequently usehistory | grep somecommandNow, my memory is pretty bad and I also want to see what else I did around the time I entered the command.For now I do this:get match, say 4992 somecommand, then I do history | grep 49[0-9][0-9]this is usually good enough, but I would much rather do it more precisely, that is see commands from 4972 to 5012, that is 20 commands before and 20 after. I am wondering if there is an easier way? I suspect, a custom script is in order, but perhaps someone else has done something similar before.

View 2 Replies View Related

General :: Write Shell Script That Give A Number Between 1-3444 From User

Feb 18, 2011

i want to write shell script that give a number between 1-3444 from user and if user enter out of range number give error e.g number must between

read -p "plz Enter Number " p
while [ $p != [1-9] -o $p != [1-9][0-9] -o $p != [1-3][0-4][0-4][0-4] ]
do
read -p "plz Enter Valid Number" p
done

but this have an error in while statement ! two many argument

View 3 Replies View Related

Ubuntu :: Write A Base Script Which Will Divide An Argument By 10 And Then Use That Argument In Another Program?

Feb 23, 2010

I'm trying to write a base script which will divide an argument by 10 and then use that argument in another program. Since my argument can be a floating point number, I used bc to accomplish this. Here's an example of a simplified version of what I have so far:

<code>NUM=$(echo "scale=25;$1/10" | bc)
#make sure the first argument was formatted correctly
if [ $? -ne 0 ]

[code]...

View 4 Replies View Related

Programming :: Argument Relations In CGI Script

Feb 15, 2010

I have made fallowing script for CGI scripting learning purpose:

Code:
#!/bin/sh
echo "Content-type: text/html"
echo
CMD='echo "$QUERY_STRING" | sed -n 's/^.*cmd=([^&]*).*$/1/p' | sed "s/%20/ /g" '
echo "<html>"
echo "<head><title>Hello CGI</title></head>"
echo "<body>" .....
echo "<input type=radio name=cmd value=ifconfig checked> ifconfig <br>"
echo "<input type=radio name=cmd value=uname> uname -a <br>"

This script works fine, but actually I quite don't understand it's inner working about those radio buttons.

View 1 Replies View Related

Programming :: Insert $2 Argument Until The End To Variable?

May 17, 2011

how to insert $2 argument until the end to variable?For example:

>> cucu.csh user "long long message "
$1 = user
$2 = "long long message "

View 10 Replies View Related

Programming :: Making A 1 Command Line Argument?

Jun 8, 2010

I need to write a script that will take 1 command line argument. The argument will be a username. The script will determine if the user exists on the system and will print an error if it does not. If the user does exist it will determine if the user is currently logged in, if the user is not logged in it will determine the last time the user logged in and display the file in the users home directory that was most recently modified.

View 2 Replies View Related

Programming :: Passing The Char * Vector Argument?

Jun 19, 2010

I am trying to simulate a shell. So what I do is checking of having the parameters from standard input, suc as "/bin/ls -l /home/france/Documents", and then passing them to function execute, which at some point calls execvp(argv[0],argv)The problem is that I don't succeed in using these arguments, while if I call execvp(paramList[0],paramList) it works!!!! Where paramList is exactly what I would put on standard input, but defined statically.

Code:

#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

[code].....

View 2 Replies View Related

Programming :: [bash] Option Followed By Argument List?

Feb 6, 2010

I'd like to pass the following arguments to a bash script in any order:

Code:
myscript -l <country> -r <file1> <file2> ... -o

I read the argument list in a switch shift loop. I figured out how to read the filelist but only if -f is the last option.

how to position the file list anywhere in the argument list?

View 5 Replies View Related

Programming :: C - User To Input The Name Of A File As An Argument

Aug 5, 2010

Write a program that requires the user to input the name of a file as an argument. If the user fails to include one argument it should make use of a thread that handles a signal. The signal handler should tells the user Incorrect number of arguments and then calls the terminate signal on the process.

If the numbers of arguments are correct then the program should allocate memory space to the file (5MB) and create a child process that requests the user for a character that it should send to the parent. The child should keep request for data until the user keys in the character O. During each request it should pause for 10 seconds, send the character to the parent and then requesting again for another character.

The parent should get the character from the child. Do not make the parent wait for the child to finish requesting for data. Make use of pipes to facilitate communication between the parent and the child. A second child should be created to read and display data from the file. Make use of any appropriate Inter Process Communication technique to ensure that the second child and the parent do not access the file simultaneously (Mutual exclusion).

View 5 Replies View Related

Programming :: CreateProcess() In C \ Specify The Location Of The File As An Argument?

Aug 31, 2010

am coding a chat program in C (win32), where I need both the client and the server to communicate, without waiting for a reply from the other side, like the way we chat in any messenger. Is there any way of accomplishing it? I tried out CreateProcess() function, but am not clear how to specify the location of the file as an argument.If there are better techniques than CreateProcess(), then

View 13 Replies View Related

Programming :: Pass Complicated Commands As Argument To Another Script?

Apr 21, 2010

I am attempting to script some tasks I have to do, but I have no control over one of the scripts I have to use... and they output all kinds of useless things on the screen. My goal is simple: Capture all output from their scripts, and create a progress line that only shows the most recent output from their stuff. So, here was my first solution; a file I called "spin":

Code:
#!/bin/bash
spinX(){
PROC=$1
STRT='date "+%s"'
while [ -d /proc/$PROC ];do
last3=" 'getLine $2' "

To use it, you pass it a process ID and a file that contains the output from that process. As the process continues, a kurby dances on the screen (To let you know that the process has not hanged), and the tail of the output is shown (To let you know what it is doing). When the process ends, the kurby stops dancing and the time it took is displayed.

And here is the file I call "noise":
Code:
#!/bin/bash
while [ i -lt 100 ];do
i=1
echo "Look at me count!$"
sleep 1
let "i=$i+1"
done

This does nothing but create random output, for testing. It counts from 1 to 99 on the screen. To run my test, I do the following:
Code:
(noise) &>tmp.txt & spin $! tmp.txt

It works relatively well, but it is messy. I don't like creating a temp file, and I don't like the messy syntax for calling my program. I decided that I would rather move everything into the spin program, to make using it less messy:
Code:
#Spin Psuedo code
#$1 = command I am about to run
(exec $1) &>tmp.txt & spinX $! tmp.txt

By executing the process inside of the spin code, I can get rid of the tmp file later on without changing a lot of scripts (Or move it, or whatever). I can also call it by passing the command to the script, which I find more elegant.

So here is what I would like to know:
1) If possible, I would love to get rid of the tmp file all together, and store the most recent line of output from script 1 into a variable that script 2 can print out instead... is it possible?
2) How can I run a random command that is passed as an argument? Basic ones work fine, but anything with a pipe fails me.

Example of a script:
Code:
#!/bin/bash
#myEcho.sh
echo;echo "Recieved command: ";echo $1;echo;
echo "Attempting to run command: ";echo
exec $1

Example code for passing commands to script:
> myEcho.sh "ls -al" #works
> myEcho.sh 'ls -al' #works
> myEcho.sh "ls -al|grep *.sh" #fail
# Output:
#ls: invalid option -- |
#Try 'ls --help' for more information.
> myEcho.sh "ls -al|grep "*.sh"" #fail
# Output:
#ls: invalid option -- |
#Try ls --help' for more information.
> myEcho.sh 'ls -al|grep *.sh' #fail
# Output:
#ls: invalid option -- |
#Try 'ls --help' for more information.

View 8 Replies View Related

Programming :: Ssh Remote Command Preserve Quoted Argument?

Sep 17, 2009

I have a python script on one server (serv_one) and I am trying to execute it remotely from another (serv_two). The python script takes an argument with spaces. If I execute it locally:

Code:

foo@serv_one> script.py --o "arg one"
"arg one" is preserved, of course. ( argv = [ '--o', 'arg one' ] )

However, when I execute it remotely:

Code:

foo@serv_two> ssh ... foo@serv_one script.py --o "arg one"

the double quotes around "arg one" are dismissed ( argv = [ '--o', 'arg', 'one' ]. I've tried many combinations of single quotes/double quotes/backslashes, etc, to no avail. One hack solution I came up with, since I have the flexibility, was to replace all spaces in the quoted argument with a character that would be invalid in the argument (before the ssh call), and replace those with spaces in script.py. I would probably like to avoid this solution if at all possible.

View 7 Replies View Related

Programming :: C++ Program Calling A Fortran Subroutine With A Function In The Argument?

Mar 9, 2011

I have a new problem; i want to call a subroutine's fortran which have a function in the argument and the compilation ran properly, but when i execute the program this shows me an "Segmentation fault". This is my c++ program:

Code: //Main.cpp
#include <stdio.h>
#include <iostream>

[code]....

View 2 Replies View Related

Programming :: Handle Non Argument Error While Adding Two Alphabets Using 'expr'

Feb 19, 2011

how to handle non argument error while adding two alphabets using 'expr' (not bc).

View 1 Replies View Related

Programming :: Shell Scripting / Create A Shell Script Similar To Ls?

Jun 5, 2011

I am trying to create a shell script similar to ls, but which only lists directories. I have the first half working (no argument version), but trying to make it accept an argument, I am failing. My logic is sound I think, but I'm missing something on the syntax.

Code:
if [ $# -eq 0 ] ; then
d=`pwd`
for i in * ; do
if test -d $d/$i ; then
echo "$i:"
code....

View 10 Replies View Related

Programming :: Bash-shell-like Less Functionality In The Python Shell?

Jun 25, 2010

Is there some type of functional way to read things in the Python shell interpreter similar to less or more in the bash (and other) command line shells?

Example:

Code:

>>> import subprocess
>>> help(subprocess)
...
[pages of stuff to read]
...

I'm hoping so as I hate scrolling and love how less works with simple keystrokes for page-up/page-down/searching etc.

View 4 Replies View Related

Programming :: Make A Template Char Or Wchar_t Default Function Argument?

Oct 30, 2009

I have a template similar to the following.

Code:

template <charT>
virtual void do_get_date(charT* = "str")
{ ... }

As you can see we have a problem. If we use a wchar_t instead the string wont be formatted right we need to prefix L in front. If we use char16_t we need to prefix a u in front. Is there a was to make the generic without resorting the the std::string class?

View 2 Replies View Related

Programming :: Out Of Range Vector Iterator?

Mar 20, 2011

I'm not really a C++ noob at all, but I am a little rusty at the moment. Still, I CANNOT figure out what is wrong with the following code. I'm using Visual Studio 2010.

Code: #include <iostream>
#include <fstream>
#include <vector>
#include <string>

[Code]....

I THINK I got all of the pertinent code. Anyway, it fails at the *** line. I CANNOT figure out why. If I modify it to be linein.size()-30, it STILL gives me an error. That makes zero sense.

View 3 Replies View Related

Programming :: How To Tell Java To Print 20 When Value Is In That Range

Jul 28, 2011

I've just started programming at my university and I'm finding it a bit hard to get started. I've been given this for homework.Given 2 integers, a and b, print their sum. However, sums in the range 10..19 inclusive, are forbidden, so in that case just print 20The problem I'm having is that i don't know how to tell java to print 20 when the value is in that range.

View 14 Replies View Related

Networking :: What Are Short Range Link And Long Range Links In Routing

Jun 23, 2009

get me understand the short range and the long range links from routing (and routing protocols') point of view.

View 6 Replies View Related

Software :: Gnuplot - Combining A Linear Range And Log-scale Range In The Same X-axis?

Apr 24, 2011

I want to plot a set of data in only one plot.The problem is that some points of the data should be better plotted in a linear scale (lets say 0 to 100,000) but there are other data points that, exceding the value 100,000, would be better plotted in a logarithmic scale, as they goes in the range 100,000 to 500,000,000. Let's say the data is:

Code:

X Y
0 100
10000 80
20000 75

[code]....

Is there a way to plot all these points in the same plot in only one X-axis showing two different ranges in that axis: linear: 0-100,000 logarithmic: 100,000 - 1,000,000,000?The axis would be read, for example, as:

Code:
|-----|-----|-----|-----|-----|-----|-----|-----|-----|
0 20k 40k 60k 80k 100k 1M 10M 100M 1G

(The abbreviations k-M-G are not the important point. Just shown for clarity)

View 2 Replies View Related

Programming :: Delete A Specific Range Of Files?

Aug 13, 2010

I have 50 files in the following format.

fileone.0001.txt
filetwo.0002.txt
filethree.0003.txt

[code]...

View 4 Replies View Related

Programming :: Replace A Certain Range Of Characters In Unix?

Mar 8, 2010

I have a hard time figuring this out. I need to replace the date formats of arrival date(column 31-40) and departure date(column 42-51) and I need 2 outputs. I cannot even figure out how to start.code...

View 6 Replies View Related

Programming :: Sed Print Range From Pattern1 To Pattern2?

Jun 14, 2011

From a file I want to extract a range of lines by patterns. I've used variations on

Code:
sed -n -e '/^BashNotes/,/^EndOf[A-Za-z]*$/ p' -e '/^EndOf[A-Za-z]*$/ q' Notes

So, I want to extract lines starting from one whose first word is specified, in this case "BashNotes", and ending at the first line consisting of the single word "EndOf...", which in this case would be "EndOfBashNotes".

Either I get no output at all, or it prints from the start of file to the first EndOf..., so the problem has to be with "^BashNotes", e.g. remove the "^" and it accesses an earlier occurrence of "BashNotes" that is in the middle of the first line of the file, and prints to the first occurrence of "EndOf...".

So why should a "^" in the "from" pattern be objectionable, when it is acceptable in the "to" pattern and the "quit" statement?

View 7 Replies View Related

Programming :: Bash: Give A Variable The Value Of A Function?

Aug 8, 2010

I was wondering if possible in bash for a variable to take the value of a function, I mean the function returns a value and a variable will take it. example:

[Code]....

View 3 Replies View Related







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