Programming :: Calling Vars In A For Loop In A Shell Script?
Oct 8, 2010
# variable declaration
stt=10
enn=20
stp=1
# I want to do it in the following structure but not sure how to call # the stt, enn and stp in a for loop
for (( i = $stt; i -le $enn; i=i + $stp ))
do
blah blah
done
View 9 Replies
ADVERTISEMENT
Jun 28, 2010
I am trying to do some shell programs. I tried some sites regarding the while loop, they give the structure as:
Code:
while [ n1 -lt 500 ]
do
echo $((n1+100))
done
But the below code also worked for me:
Code:
while ((n1 > 500))
do
echo $((n1+100))
done
By using (( )) I could use while, for. But the documentations didnt follow this way. I mainly use this for datastructure programming.
View 4 Replies
View Related
Apr 19, 2011
hint me why and how to execute the below for loop, the way i am trying to?
[bkcreddy17@local:~]$ cat -n test
1 date
2 ls -l
[code]...
View 14 Replies
View Related
Jul 22, 2011
I have written the following script in my linux server to add users for LDAP database.But i can't able to run this.
The script is as following
#!/bin/bash
echo "Mention the username which you want to convert LDIF format"
read username
if ["$username" -e "/ldiffile/passwd"]; then
echo "Username already exists"
else
cat /etc/passwd | grep -i "$username" >> /ldiffile/passwd
fi
The output which i got :
. ldapadd.sh
Mention the username which you want to convert LDIF format
yal2361
-bash: [yal2361: command not found
please let me know where need to change and what
View 5 Replies
View Related
Mar 4, 2010
Well, I am facing one issue:How can i read two files word by word at a time using any loop as i need word by word comparision in shell script?Please let me know pseudo code.
View 14 Replies
View Related
Aug 18, 2009
I have 2 shell scripts, script1.sh and script2.sh. I call script2.sh from within script1.sh ( by simple ./script2.sh command). Based on some condition, i use exit 0 to exit out of script2.sh. I was trying to find if i can exit out of script1.sh as well at once. below is the example
script1.sh
#!/bin/bash
echo "Before ..."
[code]....
When i execute below is the output
Before ...
There was problem file is empty
The Script will Exit. Please fix the issue and run again...
After ...
I am trying to exit out of script1.sh as well so that i dont print "After ..."
View 3 Replies
View Related
Jul 27, 2011
I am setting up a cron job, where i am calling a shell script to make few builds. I got struck at a point, need some expert inputs to proceed further. The script is categorized in 5 parts and in the last part while building software it asks for few questions like:-
1. Build mode choice
2. normal build
3. Copy Images
4. Arch
User manually has to input ans for these questions:-
1
yes
n
64
The ans's are fixed and this won't change. How shall i hard-code them or do something in the script so as when script flow reaches to this point it automatically take's these value. So far the cron job is not getting completed as it's waiting for user to key in these values manually. I had faced similar issue while building kernel modules but there it was easier as i had to take default values always:-
View 2 Replies
View Related
May 23, 2011
I need to execute a SQL via shell script and i am connecting to Oracle DB by this way $USERNAME1/$PASSWORD1@$STRING1 and i need to get username, password and string from someother file stored in the Unix Directory. $Username, $Password and $String is stored in File A in Path A and i want to call it in the test.sh in Path B.
Format of File A.txt
Username=test_db
Password=*****
Instance=ORACLEDB
View 3 Replies
View Related
Jun 12, 2011
I have hundreds of files in one directory, is there a simple command or pipes of command I can use to append them together? I don't want to use any loops.
View 4 Replies
View Related
Oct 20, 2010
I have just upgraded from 10.4 to 10.10 (x64), and now when I run gnu screen the new shell session goes into an infinite loop displaying:
Quote: Linux dave-desktop 2.6.35-22-generic #35-Ubuntu SMP Sat Oct 16 20:45:36 UTC 2010 x86_64 GNU/Linux
Ubuntu 10.10
Welcome to Ubuntu! * Documentation: [URL]...
0 packages can be updated.
0 updates are security updates.
repeatedly until I hit CTRL-C and break out of screen. I tried tmux and that did the same thing, so it is a problem with the shell initialisation rather than with the screen program. However I can start bash, zsh or sh directly in a terminal with no problem.
View 1 Replies
View Related
Jul 27, 2010
I'm looking to get a shell script to loop through a number of directories and subdirectories,looking for files that contain a particular substring, and renaming the file by replacing the search string with a different substring. For example if you had a directory full of folders that contained digital photos (along with various other files which would need to remain unaffected), and the intent was to remove the "DSC_" prefix from several thousand files buried within. I've whipped up a rather long-winded solution that works well for this purpose but chokes on directory names with spaces. I am reasonably sure there's a 2 or 3-liner that would accomplish this exact same task.
function investigate
{
path=$1
for file in `ls $1`
#for file in *
[code]....
View 1 Replies
View Related
Jan 19, 2011
I modified files in several directories, and need to run a diff on the backup I created before modifying the file.
I'm trying to compose a simple shell script to speed up the task, but getting a syntax error.
Here is what I have:
for i in DIR1 DIR2 DIR3 DIR4 DIR5 do;
diff /maindir/subdir/subdir/$i/filename.txt.old /maindir/subdir/subdir/$i/filename.txt;
done
I know the paths are valid, and if I run just the diff command with the actual DIR1 instead of $i it works.
View 2 Replies
View Related
Jun 4, 2010
I have a question about calling an asm function from C....It doesn't work unless I create an asm variable to hold the value of the function in....Why?Here's the code that doesn't work...
asmfile.s - version one Code: .section .data
mydata: .ascii "this is the message!
.equ mylen, . - mydata
[code]...
View 2 Replies
View Related
Feb 7, 2011
I am doing a web site program and what I need is to call a C program in the PHP cloud.Do u think it would be possible? The web site would get the user input from PHP UI and pass to the C program , the C program would process the function with the user input and output the a PHP page.
View 2 Replies
View Related
Aug 13, 2010
I want to call c exe from java source code and i want to interact with the c program during it's execution, i am able to send the parameters to c program but i am not able to interact with it.
View 3 Replies
View Related
Feb 17, 2011
I have found a weird behaviour on a linux application. A tty seems to get closed without calling close. The program is (very simplified) as follows:
Process 1:
configure_signals()
read_config_files()
create_threads()
wait(forever)
Thread 1:
fd=open(/dev/ttyXX)
usleep(a while)
config(fd)
I have spent quite a lot of time on this problem. It seems like the file is sometimes closed when reaching config(fd), but removing the usleep(a while) seems to remove the problem.
View 1 Replies
View Related
Jul 17, 2010
I have a bash script that changes the iptables.Now i call this bash script in my php code.When this bash script is running the part of code that contains iptables instruction is not running because we need to be in superuser mode(root)
View 14 Replies
View Related
Apr 15, 2009
I'm trying to call some Fortran 95 code in C, but I'm having problems with integers not having the same value in C as in Fortran, and changing values upon each run of the program. I think it has to do with the integer type, but I don't know how to fix it. I'm running Gentoo x86. Here are the files I've got:
foo.c:
Code:
#include <stdio.h>
extern int qux_();
main() {
[code]....
View 2 Replies
View Related
Aug 19, 2010
What is the difference in perl between:
'function();'
and
'&function();'
with and without ampersand.
View 1 Replies
View Related
Jul 30, 2011
i use the sockaddr_in like this before calling bind(), it works good.
Code:
sockaddr_in serveraddr;
serveraddr.sin_port=htons(5000);
serveraddr.sin_addr.s_addr=htonl(INADDR_ANY);
serveraddr.sin_family=AF_INET;
[Code]....
View 2 Replies
View Related
Apr 9, 2010
I am trying to call a script say mkdir.sh into another script that will make use of the dir's which are created in the first script. I know that I could code it all together, but I am trying to avoid rewriting the mkdir script as it is long.
View 7 Replies
View Related
May 20, 2010
I'm trying to call a system command in perl and am having an issue with it.
Here's an example of a command i'd like to call: Code: sed -i '4 c192.168.1.4 www.something.com' hosts this is the section in my perl script where I create the variable and call it: Code: $doit = `sed -i '$line c$ip $host hosts'`system($doit); The $line, $ip, and $host variables are working fine becasue I can replace that section with "prints" and they come out fine. I imagine the problem is where I am creating the $doit variable.
View 7 Replies
View Related
Jan 21, 2011
I want to call a subroutine in Fortran 90 from a c++ code. I can do it, when the fortran code have no module. But i need to call the subroutine in a fortran code that have an module. I have a simple program that shows my problem. The Fortran code is:
Code: !add2.f90
Module add2
Implicit none
Contains
[code]....
collect2: ld returned 1 exit status I Dont know where is the problem. Maybe it is in the call of the function. I found that the syntax have this form: extern void __namemodule__NMOD_namesubrutine(arg)
View 6 Replies
View Related
Apr 11, 2011
I feel like there should be a cleaner way of doing this. I have one file, for example "a.cpp", calling a function from another file, "b.cpp". Currently I have it set up so that header for "b", "b.h", has the declaration of its functions. And then I'm just including "b.h" in "a.cpp". Do I have to include the "b" header file in "a" to be able to call a function from "b"? Or is there a better way I could be doing this? Like doing something different at compile?
View 7 Replies
View Related
Oct 4, 2010
I am trying to use a software package written in ANSI C. It has a makefile which has to be executed first.
As soon as I execute it I get messages like: line i: command not found.
Commands for which I am getting errors :
CC = /usr/bin/gcc
GCCFLAGS = -c -Wall
ROOTDIR = .
My gcc compiler is located in the above directory only. In ROOTDIR also I tried giving the path in which all the required files & folders are present but still I get the command not found error in all the lines.
View 7 Replies
View Related
Feb 5, 2010
I'm trying to call some kernel functions from userspace, but I'm not sure if I'm doing it right. The functions control a pulse width modulator on an embedded platform. To pick one at random, the function:
Code:
struct pwm_device *pwm_request(int pwm_id, const char *label);
is defined in linux/pwm.h, and the implementation uses the macro EXPORT_SYMBOL(pwm_request), so I should be able to call this from user-space... right?
Anyway, I've got linux/pwm.h to #include in my source so the compiler knows what it's doing, but what do I link against? The only place in by kernel build tree where I can see a symbol pwm_request defined is in object files like vmlinux.o, built-in.o in the directory, etc. which I don't think I should be linking against.
View 2 Replies
View Related
Oct 29, 2010
I have written FORTRAN code to calculate density profile. This code will open two files ( topology and x,y,z trajectory). The trajectory file contains XYZ data coordinates for multiple frames (about 20 or 100 frames for instance). One frame contains 20736 data.
Previously this code was written to open ONLY one input XYZ data file and do the calculation and would dump the results in separate file and it was running without problem. Recently my data file get bigger in size, so I decided to break the single XYZ data file into few small parts.
Now I have modified the code so that it calls the parts of the XYZ data files ( eg: maltoTHERMO_10Frames.traj, maltoTHERMO_20Frames.traj,... and so on) and do the calculation and dump the results in the same result output file. I have tested this code just with openning the XYZ coordinates and printing into another file to see wheather it collecting the data sequently and it was working fine.
This code supposedly read the x coordinate data and calculate distance and put a count accoding the criteria in the approperiate bins. But when I let the code to do the calculation it stop and shows error. (I have indicated as !** in the code). If I enable this line, it shows error but if I disable this line, than the code do collect only the XYZ coordinates.
The code is as below:
Code:
module all_parameter
integer,parameter :: MAXATOM=20736!CHANGE
integer,parameter :: midwater=1500
integer,parameter :: TOTALFRAMES=20
[Code]....
View 8 Replies
View Related
Mar 2, 2011
I have typed the following code:
Code:
<html>
<form enctype="multipart/form-data" action="upload.php" method="POST">
[code]...
View 3 Replies
View Related
Oct 17, 2010
lets look at code in C
Code:
#include <stdio.h>
#include <stdlib.h>
[code]...
View 3 Replies
View Related
May 5, 2010
I am trying to play with calling text files in C. What I have is a text file with 4 columns of numbers I need to average 2 of them. I have started and hit a wall. I have the following so far:
[Code]....
I still need to figure out how to read the data in. I have been reading on this for a few hours and its not clicking. How does the program know which columns with names to call. the data is organized: ID, Day, Speed, Temp.
View 6 Replies
View Related