Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
echo "line 1" echo "line 2' [output] line 1 line 2 Question: Can i move to line 1 and change '1' to '3' without damaging the line 2?...
  1. #1
    Just Joined!
    Join Date
    Nov 2008
    Posts
    37

    Can I move to a previous line in shell script?

    echo "line 1"
    echo "line 2'
    [output]
    line 1
    line 2


    Question: Can i move to line 1 and change '1' to '3' without damaging the line 2?

  2. #2
    Linux User dxqcanada's Avatar
    Join Date
    Sep 2006
    Location
    Canada
    Posts
    259
    Is this a question about how to use a specific text editor ?



    Men occasionally stumble over the truth,
    but most of them pick themselves up
    and hurry off as if nothing had happened.

    Winston Churchill


    ... then the Unix-Gods created "man" ...

  3. #3
    Just Joined!
    Join Date
    Nov 2008
    Posts
    37
    I want to print in the line 1 again without damaging line 2 in a shell script in console or terminal

  4. #4
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047
    Interesting question. I wouldn't know. Usually I clear the screen and start anew. It works.

    Something like this:
    Code:
    VAR1="1"
    VAR2="2"
    
    ShowOutput () {
    clear
    cat << EOF
    $VAR1
    $VAR2
    EOF
    }
    
    SimpleLoop () {
    while true ; do
    echo -n "What do you want as first variable? "
    read -n 1 VAR1
    ShowOutput
    done
    }
    
    SimpleLoop
    Can't tell an OS by it's GUI

  5. #5
    Just Joined!
    Join Date
    Nov 2008
    Posts
    37
    Very nice.... thanks...

    But this is not im looking for...

    Consider a wave motion starting in first line and moving to second line and again first line and again second line like wise...........
    example:
    \ /\ /\
    V V
    Like this wave motion... starting from first line and going to second and then move to first line again and again second, first etc..etc.........

    I Think i can make this with your method but im not sure about it, i want to spend little time with it to be conformed. And also i want to know that whether is there any command or simple method to move to the previous line

    thanks for your reply.......

  6. #6
    Just Joined!
    Join Date
    Nov 2008
    Posts
    37
    Very nice.... thanks...

    But this is not im looking for...

    Consider a wave motion starting in first line and moving to second line and again first line and again second line like wise...........
    example:
    Quote Originally Posted by sky_knight02 View Post
    \ /\ /\
    V V
    Like this wave motion... starting from first line and going to second and then move to first line again and again second, first etc..etc.........

    I Think i can make this with your method but im not sure about it, i want to spend little time with it to be conformed. And also i want to know that whether is there any command or simple method to move to the previous line

    thanks for your reply.......

  7. #7
    Just Joined!
    Join Date
    Nov 2008
    Posts
    37
    Can you please tell me the role of `cat << EOF and EOF here, I dont know what they are and why they are used for.

  8. #8
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047
    Quote Originally Posted by sky_knight02
    Can you please tell me the role of `cat << EOF and EOF here
    When you want to output multiple lines, the cat OEF combo gives a cleaner look in the script and is easier when you want to insert lines, that's all. You could also put 'echo' on every line. It's the same.


    As for what you want, well it's possible. Is it a repeating patern or a progressive pattern?

    Repeating is very easy, just alternate between two different values in the variable.

    If you want a progressive pattern, sort of like a character moving, then you need to put some effort in structuring it (hint: it's all about counting)

    Code:
    #!/bin/bash
    opt="x"
    alt="0"
    var="0"
    while [ "$alt" -le "11" ] ; do
    	while [ "$var" -le "10" ] ; do
    		var=`expr $var + 1`
    		if [ "$alt" -eq "$var" ] ; then
    			opt="X"
    		else
    			opt="x"
    		fi
    		echo -n $opt
    	done
    var="0"
    alt=`expr $alt + 1`
    sleep 0.2
    clear
    done
    This will get you a moving X in a row of x's. Not particularly useful I'm afraid. But it is how I would get movement in a standard bash script output.

    If you make it too big, then refresh rate gets a problem. So if anyone knows the answer to your original question? I bet there are better ways to do this.
    Can't tell an OS by it's GUI

  9. #9
    Just Joined!
    Join Date
    Nov 2008
    Posts
    37
    Thanks Freston.... this helped me a lot... ill let you know when i find it....

    I hope some one will reply with the right answer.....

  10. #10
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    It sounds like you want to move the cursor.

    One way to move the cursor around is to use tput. See Discover tput or Google for tput topics ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...