Error in script, STUCK :(


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error in script, STUCK :(
# 15  
Old 08-16-2012
Quote:
Code:
sed -e 's/file$i/file$(i+1)/g'

First: replace single quotes with double quotes: this way the "$" will mantain its special value.
Second: use the arithmetic expansion syntax:
Code:
sed -e "s/file$i/file$((i+1))/g"

or:
Code:
sed -e "s/file$i/file$(($i+1))/g"

which are the same thing.
--
Bye
# 16  
Old 08-16-2012
Quote:
Originally Posted by Lem
First: replace single quotes with double quotes: this way the "$" will mantain its special value.
Second: use the arithmetic expansion syntax:
Code:
sed -e "s/file$i/file$((i+1))/g"

or:
Code:
sed -e "s/file$i/file$(($i+1))/g"

which are the same thing.
--
Bye
Perfect, Got it..SmilieSmilie Working all fine..

Thanks,
Pooja

---------- Post updated at 04:28 PM ---------- Previous update was at 02:52 PM ----------

Hi all,
I am completely messed up. SmilieSmilie
I wrote this script locally where I used the bash SHELL. But originally I need to use it at some other machine where the SHELL is tcsh. SmilieSmilie

tcsh is totally new for me. if somebody here know tcsh scripting and can help me. It would save lot of my time.

Thanks in advance
pooja

working script in bashrc
Code:
#!/bin/bash
date
cd /home/poojasaxena/Desktop/CMS/script/DataMCMatch/

FILE=$1
TARGETPATH=$2

function pause(){
   read -p "$*"
}

max=3
for (( i=0; i<=$max; ++i )) ; 
do
    echo "SHELL SCRIPTING ================ $i ==============" 
    cp $FILE $TARGETPATH
    
    if [ $i == 0 ]; then
	source $TARGETPATH
	pause 'Press [Enter] key to continue...'
        rm $TARGETPATH
	
    else
	if [ $i > 0 ]; then
	    { rm card_Data2011AB_Zee_40GeV; sed -e "s/file$i/file$((i+1))/g" > card_Data2011AB_Zee_40GeV; } < card_Data2011AB_Zee_40GeV
	    source $TARGETPATH
	    pause 'Press [Enter] key to continue...'
	    rm $TARGETPATH
	else
	    echo "Its About To Terminate...Enjoy Scripting"
	fi
    fi
done

# 17  
Old 08-16-2012
Quote:
Originally Posted by nrjrasaxena
I wrote this script locally where I used the bash SHELL. But originally I need to use it at some other machine where the SHELL is tcsh. SmilieSmilie
tcsh isn't even a bourne shell.

If the machine is UNIX at all, it will have a /bin/sh or at least some sort of sh, you don't have to use tcsh.

Otherwise, you're starting over from scratch.
# 18  
Old 08-16-2012
Hi,
yeah, Machine is UNIX. I being a physics student not much aware of this stuff.
For example, I do not know if I can run this script at all in tcsh SHELL based machine.
I already started form scratch [1], script showing error in "if" command. My unlucky day Smilie


[1]
Code:
#!/bin/tcsh
date

# cd /uscms_data/d3/pooja04/Area4VGamma/CMSSW_4_2_8_patch7/src/ElectroWeakAnalysis/MultiBosons/
# source /uscmst1/prod/sw/cms/setup/cshrc prod
# cmsenv

# Code Directory
cd /uscms/home/pooja04/script/TagProbe/KuanCode/test/WithJson/2012/version4/data/v5/

################################################################################################################

# FILE = file.sh whhich execute 'root -l RunAnaVgNtuple.C'
# TARGETPATH = temp copy of file.sh
echo "0"
set FILE=$1
set TARGETPATH=$2
echo "1"

#function pause(){
#read -p "$*"
#}
echo "2"
set max=12

    foreach i (1 2 3 4 5 6 7 8 )
    #    do
    echo "SHELL SCRIPTING ================ $i ==============" 
    cp $FILE $TARGETPATH
    echo "is it "
    if ( i < 1 ) then
        echo "4"
        source $TARGETPATH
        echo "5"
#        pause 'Press [Enter] key to continue...'
        echo "6"
        rm $TARGETPATH

    else if ( $i > 0 ) then
        { rm card_Data2011AB_Zee_40GeV; sed -e "s/file$i/file$((i+1))/g" > card_Data2011AB_Zee_40GeV; } < card_Data2011AB_Zee_40GeV
        source $TARGETPATH
        pause 'Press [Enter] key to continue...'
        rm $TARGETPATH
    else
        echo "Its About To Terminate...Enjoy Scripting"
    endif
    end

# 19  
Old 08-19-2012
Quote:
Originally Posted by nrjrasaxena
Hi,
yeah, Machine is UNIX. I being a physics student not much aware of this stuff.
For example, I do not know if I can run this script at all in tcsh SHELL based machine.
If the machine is UNIX at all, it will have a /bin/sh or at least some sort of sh, you don't have to use tcsh.

Try which sh or whereis sh
# 20  
Old 08-19-2012
Hi,
Here are the output of the folllowing commands:

Code:
[pooja04@cmslpc06 ~]$ which sh
/bin/sh
[pooja04@cmslpc06 ~]$ whereis sh
sh: /bin/sh /usr/share/man/man1/sh.1.gz /usr/share/man/man1p/sh.1p.gz
[pooja04@cmslpc06 ~]$

So even if there is sh shell, how it should be switched from tcsh to bash?

thanks
# 21  
Old 08-19-2012
Please post what Operating System and version you are running:
Code:
uname -a  # Blotting anything confidential like machine names with Xs

And whether you have the bash Shell:
Code:
which bash

Though we can guess that this is likely to a version of Sun/Oracle Solaris, the more background information the better.

As others advise, Bourne Shell script (i.e. the norm for systems admin scripts on unix and Linux systems) will not work in your "C Shell" tcsh.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Check for updation/error/stuck of logs

Hi All, I'm a newbie in Linux Programming.:) Got some 500 processes running and I have around 20-30 logs updating for every 2mins on a server. The logs which i'm referring usually contains book name,run ids(not PID's),process name etc etc. I'm interested in finding out whether some particular... (1 Reply)
Discussion started by: Nand Kishor
1 Replies

2. Shell Programming and Scripting

stuck on first script with sed issue

Hi, I'm developing my first bash script and have made good progress but stuck at this point. I've run sed on a text file to extract some data and have saved it into a variable e.g. $blah the variable contains emails as follows e.g. <a@b.com> <b@c.com> I'm now trying to edit... (2 Replies)
Discussion started by: newb1000
2 Replies

3. Shell Programming and Scripting

Script to Output Files That Have Got Stuck

Hi, I need to create a script that we will schedule to run say every 30 mins to check a directory for files that have been present for a set period of time. Situation we have is that we have an input folder where files are processed from and once processed they get moved to a done folder,... (1 Reply)
Discussion started by: everythingno
1 Replies

4. Shell Programming and Scripting

Stuck in this shell script - please help

hi: I'm trying to write a shell script that recognizes all .txt files in all the subdirectories in my current directory. Let's say that i have a directory called Applications which consists of many subdirectories on mnay levels. i want the shell script to look for all .txt files that exist... (14 Replies)
Discussion started by: miss_dodi
14 Replies

5. Shell Programming and Scripting

Script Stuck In Loop

Hi all! Im trying to get this script to check for folders in a year/month/day folder structure and if the day doesnt exist then it makes the day. It will also make sure all of the days before todays date exist as well. This script assumes that the month and year folder already exist. It works... (3 Replies)
Discussion started by: Grizzly
3 Replies

6. Homework & Coursework Questions

i get stuck with this shell script code

i get stuck here . Anyone could check my work? the user type a group of upper case letters at a time with 0 at the end. Find and display the first letter in alphabetic order. For example, input of F, G, K, S, U, G, D, Q, P , the result should be D Any invalid input character (eg. #, $, 3, a,... (5 Replies)
Discussion started by: sbcvn
5 Replies

7. Shell Programming and Scripting

I am stuck in my script

Hi All I have script that find 777 dir with specific extension like .php .Now after finding all 777 directory i will place in httpd.conf using a directory directive ,Now i was not do that,if directory entry exitst in httpd.conf then script ignor it dont show me at stdout else if it dont find... (2 Replies)
Discussion started by: aliahsan81
2 Replies

8. UNIX for Dummies Questions & Answers

stuck with a script

Hi There I am pretty new to UNIX and have only been using it from a basic point of view,I now want to start using it and learning more , have got a whole lot of books and documentation from the web and am slowly learning.I have written a get script in windows :- lcd E:\MAIN\PRO\FILES\MAINDB... (1 Reply)
Discussion started by: FOCKER
1 Replies

9. Shell Programming and Scripting

simple script but am stuck

hey i am a bit stuck here. i just started work experience and i need to create a simple script which delete all files in a specify folder which are older then 2 days. :mad: i tried but it never works!!! anyone! i dont know much but unix since i mostly work on NT here but i dont wanna disapoint my... (2 Replies)
Discussion started by: GermanJulian
2 Replies

10. Shell Programming and Scripting

stuck on ksh script

hi, i need help to write script in korn shell that will display info. on system paging, system process table.system file table inf. thank you (1 Reply)
Discussion started by: neer45
1 Replies
Login or Register to Ask a Question