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.
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?
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"
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?
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.
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.
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 ]
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.
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.
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).
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
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":
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.
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' ] )
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.
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:
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....
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.
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?
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.
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.
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.
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:
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...
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?
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: