Software :: Bash Scripting And Integer Variables?

Jun 6, 2010

Are there numerical variables (like type int in C) in the shell script language of bash? Say I want a counter to increment each time a loop is traversed.

View 1 Replies


ADVERTISEMENT

Debian :: BASH Scripting - How To Use Variables With Filename Spaces

Jun 25, 2015

I am trying to create scripts to move files over from one directory to an ftp server and there is this one file with spaces that bash is see each word as being a file, here is the variable i am trying to use:

Code: Select allLOCL = '/mnt/cifs/"File name with spaces"/'
cd  $LOCL
ls -l

View 3 Replies View Related

Ubuntu :: Adding Strings To The Front And End Of Variables In Bash Scripting?

Mar 3, 2010

How do you add strings to the front and end of variables in bash scripting? for example, if I have

Code:

in as the contents of my variable, I want to add "l" to the front and "k" to the back of the contents.

View 1 Replies View Related

Ubuntu :: Bash Script With Variables And Editing Variables

Apr 6, 2011

mkvmerge -o <filename without extension>_TV.mkv -S <filename> && mkvextract tracks <filename> 3:<filename without extension>.*** && perl /home/brian/Desktop/ass2srt.pl <filename without extension>.*** && rm <filename without extension>.***

Doing these commands for multiple command line file inputs is the goal. So I can just type ./script.sh *.mkv in my terminal.This is what I have so far, but it doesn't work whatsoever.

View 2 Replies View Related

Programming :: C-shell Scripting Syntax Error When Defining Two Variables A1 And A2

Apr 5, 2011

I am trying to modify a script for research purposes and am having difficulty here as I have little prior experience with C-shell scripting.

The script looks as follows (it includes tcl commands like runFEP that you can ignore)

#!/bin/bash

for ((old=1, new=2; old<=4; old++,new++))
a1=${old}%50
a2=${new}%50
do
cat > input${new}.conf <<EOF
${a1}
code....

My question: I keep getting a syntax error when defining my two variables a1 and a2. I essentially need these variables to be
a1 = value of variable old divided by 50
a2 = value of variable new divided by 50

View 1 Replies View Related

Programming :: Reading A Bash Variable In Bash Scripting ?

Nov 26, 2008

I have a config file that contains:

my.config:

Code:

Now in my bash script, I want to get the output /home/user instead of $HOME once read. So far, I have managed to get the $HOME variable but I can't get it to echo the variable. All I get is the output $HOME.

Here is my parse_cmd script:

Code:

View 3 Replies View Related

Ubuntu :: Bash Scripting Gives Bad Substitution

Feb 18, 2011

I'm trying to get the substring of a string in bash. Here is the code:
Code:
#! /bin/bash
LOCAL_HOSTNAME=$(hostname)
echo $LOCAL_HOSTNAME
INDEX_OF=`expr index "$LOCAL_HOSTNAME" 1`
echo $INDEX_OF
SERVER_HOSTNAME=${LOCAL_HOSTNAME:0:INDEX_OF}
echo $SERVER_HOSTNAME

It's supposed to get the current hostname, assign it to variable LOCAL_HOSTNAME, get the first occurrence of "1" from hostname and assign value to INDEX_OF, the get the substring from variable LOCAL_HOSTNAME (starting at index 0 through INDEX_OF) and asign it to SERVER_HOSTNAME. No matter how much I've tried it keeps throwing Bad substitution error at the substring. I've searched and it says it has to be bash... but it is bash, both the sh script and the running shell. The LOCAL_HOSTNAME and INDEX_OF variables are ok.

Here is the output:
I've also tried to get the substring without the INDEX_OF but it gives the same error: SERVER_HOSTNAME=${LOCAL_HOSTNAME:0}
Code:
host1
5
test.sh: 7: Bad substitution

View 2 Replies View Related

General :: What Is Purpose Of Bash Scripting?

May 15, 2010

What is the purpose of bash scripting? Is it just for file manipulation?

View 4 Replies View Related

Programming :: Scripting The Email With Bash?

Jul 8, 2010

I need to find a way to download the attachment from a daily report e-mail to me. The kicker is it will need to be down with a cron tabbed bash script.For example, which linux based CLI client is best suited to be scripted?

View 2 Replies View Related

General :: How To Set Incrontab In Bash Scripting

Mar 7, 2011

I have a question;

Is it possible to set incrontab in bash script? I tried to set normal crontab and it works like a charm but unfortunately not "incrontab"

I have two bash files; test-incrontab.sh and addlinetocrontab.sh and here are the contents of these files respectively;

Code:

Code:

As you can see there are two enteries in each file. One for normal crontab and other one for incrontab. When i run "test-incrontab.sh" like following;

Code:

crontab works perfectly and i can see cron job set but for incrontab it just does not work. No error either!

I am only getting this back "table unchanged"

View 2 Replies View Related

Programming :: Bash Scripting: How To Keep Leading 0 On ' And '

Jan 27, 2010

I'm trying to put together a script that will quickly run through an archive directory of log files that are named by day of the month 01.gz, 02.gz, 03.gz.... 31.gz. The script uses gunzip -c | grep | wc to count up the total number of hourly occurrences of a filename and outputs the results to stdout.

The only snag I have left is the octal limit when it gets to 08 and 09. I've seen examples using perl and awk, but this script uses a number of nested for loops and if statements that I don't want to have to rewrite in a different syntax. I found that I can use num=10#08 to set that variable to a base 10 instead of a base 8, but then I lose the leading 0 again when it passes the number to the next filename variable.

View 8 Replies View Related

General :: Referring To Variables In Bash?

Sep 13, 2010

Is there a difference when variables are referred to as $variableName and ${variableName} in bash?

View 1 Replies View Related

Debian Programming :: Bash Scripting For Jessie

Aug 25, 2015

You are probably using systemd (check it with ps --pid 1) and therefore /etc/init.d isn't considered for autostart. Here can you find some information about systemd and autostart [1]. As far as I know systemd isn't intended to start applications with systemd. I recommend you to use the autostart feature of your window manager or desktop environment or at least the .xinitrc.

[URL] ....

View 7 Replies View Related

Ubuntu :: Loop Commands In Bash Scripting?

May 15, 2010

What is the difference between For and While when creating loops in bash scripting?

View 1 Replies View Related

Ubuntu :: Image Manipulation In Bash Scripting?

Jul 5, 2010

I have a bash script that inserts some text onto every image at a certain place within a directory.

Heres what I have (from a German friend who appears online once in a blue moon), this is the line that resizes to a maximum of 800 either width or height and puts in the text 'text goes here'.

convert ${bild} -resize "800x800>" -strip -family Arial -pointsize 16 -draw "gravity southeast fill rgba(255,0,0, 1.0) text 10,10 'text goes here'" ${dstdir}/${bild}

Now, I would like to know how to place a PNG image (a watermark, so to speak) over all images within a directory in a certain place, so how would I go about modifying this line to place an image instead of the text?

View 9 Replies View Related

General :: Bash Scripting - Grab First And Last Number?

Jan 13, 2011

I'm trying to get an output of a file in numeric order. Basically I need the starting number and the ending number in sed this into anther file. The test2.lis file I'm just awk'ing for the first row and if its out of order put it in order so I can grab the first and last numbers. I'm sure I can do this all in an array. The first sed command gets rid of blank lines and outputs it to a file. Then I head and tail for the first and last number then I want to sed those numbers into a file that exsist.

[code]...

The error I get is:

sed: -e expression #1, char 24: unterminated `s' command.

View 13 Replies View Related

General :: Bash Scripting / A Command That Can Stop Others?

Mar 31, 2010

i would like to ask something very simple i hope for most off you but i couldn't find anything in other questions so specific...

So...i need a command to stop another command.

more specific i have to run airodump-ng and i want this command to stop after some seconds (or minutes) automatically....

View 6 Replies View Related

General :: Combine Bash Scripting With Apache?

Apr 3, 2011

how to combine bash scripting with apache.

View 5 Replies View Related

General :: Bash Shell Scripting Request?

Feb 27, 2011

I am working on a simple script that should take two command line arguments, a [number] and a [name]. The first thing the script should do is check to make sure that no more and no less than two command line arguments have been entered when calling the script - an error message should be delivered if the condition is not true.

If two args have been entered, then the message 'processing "scriptname"' should appear, where scriptname is the name of the script being called. The script should then write to the screen "Hi [name]!", and should write this phrase [number] of times. For example, the command $ myscript 2 joe would produce the output: I have read the manual many times looking for examples, and I am very close by virtue of my own efforts. Further, I have searched these forums and others for good examples, which have also gotten me very close. Still my script is not completing the objective, and I am wondering if someone could point me in the right direction. Script:

[Code]...

View 13 Replies View Related

Programming :: BASH Scripting - Creating A Map Tree?

May 7, 2011

looking to write a dependency map tree that creates a tree structure of object names . This tree will be written to a file and read back to create the tree structure of files . how to write this using bash ?

View 1 Replies View Related

Programming :: Bash Scripting: Menu From File?

May 29, 2011

I have a file called list.txt with on word on each line that changes in length. I'd like to make a menu, each line being its own choice. I pieced together most of it the only thing missing is a failsafe for typing a number out of range

Code:
#!/bin/bash
p=`cat list.txt | awk '{print$1}'`

[code]....

View 2 Replies View Related

Programming :: Bash Scripting - Pointed In The Right Direction?

Jul 6, 2011

I've been using Ubuntu for about 6 months now, but haven't had a need to start scripting until just recently. I know programming basics, but that's about it.Anyway, I have a program that I would normally run in this manner (note that I didn't create a permanent alias because I've been moving the program around a lot):alias dx='python /path/to/dxProgram.py' dx A_input.dx B_input.dxSo, you see, program dx takes two input files, and 'A' must come before 'B'. I have a folder full of these types of files that I'd like to loop through with this program. They're named as follows:

0_A_input.dx
0_B_input.dx
1_A_input.dx

[code]....

View 6 Replies View Related

General :: Join 2 Variables In A Bash Script?

Aug 12, 2011

I have $db and $DATE set in my bash script, then I need to join them like this: mysqldump --user=usr --password=pss --databases $db | gzip > /backups/sqlNew/$db_$DATE.sql.gz;

Unfortunately, that doesn't work. How do I properly join those 2 variables into a filename?

View 1 Replies View Related

Ubuntu :: BASH Script Not Recognizing Variables

Jul 25, 2011

I'm trying to write a bash script, and for some reason Bash doesn't seem to like any of my variables _except_ the one used in a loop.What's going on? The same problem with MYS occurs regardless of its name, whether it is declared or referenced before, after, or inside the loop, and whether it is a string, integer, or floating-point number. Also, as far as I can tell, everything related to Bash is up to date.

View 7 Replies View Related

Ubuntu :: Variables In Bash Alises Not Working With 11.04

Jul 26, 2011

I am trying to use the following bash alias:

I've been able to get this working under mac and solaris.

I've also tried not escaping the vars.

Anyone know if this is doable with ubuntu's bash shell? (or any meaningful workaround other than writing a script for this?)

View 2 Replies View Related

Programming :: Using Grep / Variables In Bash Script

May 10, 2010

I'm trying to write a bash script and I'm having trouble with it.I have a list of DNS entires from a file called zoneExport.txt.Than I want to parse a log file to see if that DNS entry has been queried for. So I'm running a grep command and trying to save it into a variable. What I'm looking for is a variable ($varGrepQ) that has the number of matches for the grep query. I will then run this through an if statement and do some things from there..

But my problem right now is with this grep query. It keeps outputting '0' even when I know there are records in that file and when I run the same query on the command line I get the actual count. My thought is that the $record variable is not passing right.

View 4 Replies View Related

Programming :: Counting Variables In Bash Script

Nov 13, 2010

If I read in variables entered by the user, how can I check to make sure the correct number of variables were entered? For example, after reading in a data file and making it into an array, I have:echo "To check the data, enter the first element number, last element number and step size as x y z:"read x y z.It then goes on to start a loop, but what I would like now (before the loop) is a check to see if three variables have been entered, before the rest of the script continues.

I've tried specifying the variables as $1, $2 and $3, but if I echo $#, the value comes out as zero, so it's obviously not working.

View 9 Replies View Related

General :: Declare Global Variables In Bash?

Jan 23, 2010

I have a problem with a very big script I wrote in bash, and now I need to modulirize it in at least four smaller scripts. The problem is, that most of the variables I have will need to be shared by all scripts.

My question is: is there a way to declare global variables in bash? So that I can use and change them in any of the scripts and every change in the variable can be "seen" by the other scripts later.

View 4 Replies View Related

General :: Dynamic Variables And Heredocuments In Bash?

Apr 4, 2011

I've created a script that put in dynamic variables the value HELLO 1, HELLO 2 HELLO 5. And I put the values of this variables in the file text.txt. Here's the script:

Code:
for i in $(seq 1 5); do eval ${i}=$(cat << EOF "HELLO" $i EOF); done
cat > text.txt << EOF
$1
$2

[Code]...

View 1 Replies View Related

General :: Possible To Pass JavaScript Variables To Bash?

Apr 18, 2011

Can I pass javascript variables to bash script? If possible in bash script what code should I insert to receive javascript variables.

View 14 Replies View Related







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