A copy paste problem with loops in bash


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers A copy paste problem with loops in bash
# 1  
Old 07-21-2010
A copy paste problem with loops in bash

Hello All,

i have a really strange copy paste problem. When I write some loops in an editor for example:

Code:
for j in 1 2 3
do
  echo "$j"
done

and I want to paste it to the shell, the result in the shell is:

Code:
for j in 1 2 3; do e;

other commands work fine and if a copy paste the loop like this:

Code:
for j in 1 2 3; do echo "$j"; done

it works to. I probably disabled line breaks somehow by accident?

Any hints would be greatly appreciated,

Thanks Johannes
# 2  
Old 07-21-2010
What OS, what editor, which version of BASH, exactly how are you copying and pasting....
# 3  
Old 07-21-2010
Hi,
thanks for your reply:

Bash-Version:
Code:
/bin/bash --version
GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)

OS: Lubunut 9.10

Editor: gedit 2.30.3

Copy/paste method: I used the middle mouse button and also to cut: crtl+c and to paste ctrl+shift+v

I tried the following again:

Code:
	for j in 1 3 5
	do
		echo $j
	done

This worked.

Then I tried:
Code:
for i in 1 2 3
do
	for j in 1 3 5
	do
		echo $i
		echo $j
	done
done

This didn't work and I got the same error as described above.

And afterwards the first (unnested) loop didn't work either.

Thanks for your help J
# 4  
Old 07-21-2010
ok - this threw me.. got someone local with same setup to test an we saw no issues...

however, a bit of poking about suggests that you are using tabs, so when you copy/paste into the shell it's trying to do a bash tab completion, and barfing your input...

try changing your leading tabs ( in fact any tabs in your code) to spaces and let me know if this solves the issue....

Cheers
# 5  
Old 07-21-2010
You were absolutely right!

Exchanging tabs with spaces solved the problem.

Thanks a lot for that
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash copy and paste text in file from one position to another

Hi I have a text file with lines beginning with 71303, 71403, 71602, I need to copy the 10 digit text at position 30 on lines beginning with 71303 (5500011446) to position 99 on every line beginning with 71602 (see example below), There may be many 71303 lines but I need the text copying to... (2 Replies)
Discussion started by: firefox2k2
2 Replies

2. UNIX for Dummies Questions & Answers

Copy/paste in vi editor

Hello guys, I am trying to copy a line in vi editor and paste it with below commands but paste command is not working and instead of paste action prints the p character!! I should also mention that the server is Solaris... 1) crontab -e 2) j to move down 3) yy to copy the line 4) o to... (4 Replies)
Discussion started by: Newman
4 Replies

3. Shell Programming and Scripting

Copy and paste data

I need to copy from specified lines and paste the data into several other lines. XX123450008 xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x XX123451895 xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x xx.x ...... XX123452012 xx.x xx.x xx.x xx.x xx.x xx.x xx.x... (13 Replies)
Discussion started by: ncwxpanther
13 Replies

4. Shell Programming and Scripting

Copy and Paste to a new document

Hello, I am quite new to shell scripting so don't know all the tools available. What I'm trying to do is open a file optimal.txt search for objectiveValue and copy the number in quotes next to it. e.g. ... solutionName="incumbent" solutionIndex="-1" objectiveValue="13246" ... (6 Replies)
Discussion started by: StephanR
6 Replies

5. UNIX for Dummies Questions & Answers

Copy/Paste in Vi editor

Dear All, I have a file containing 12 lines. First 3 lines have 9 values and the remaining 9 lines with no values. I was trying to copy and paste these 9 values of the first 3 lines into last 9 lines simultaneously as A=1.491331, B=1.539000 ..... but I don't know how to cope with this... (9 Replies)
Discussion started by: sullah
9 Replies

6. UNIX for Dummies Questions & Answers

vi copy/paste problem

I'm having a problem copy/pasting from a txt file in windows to vi. What happens is I copy a chunk of text, go to the putty terminal, go into insert mode, and right click, and it will stop pasting at a random point and freeze up. Nothing I do gets out of it. This only happens on my account... (1 Reply)
Discussion started by: solidarity
1 Replies

7. Shell Programming and Scripting

copy/paste with awk

Hi everybody, I have two XML files. I am working on a script that could copy and paste the contents of the first xml file to the desired location in the second xml file. Here is my first XML file. This is the second XML file. Finaly, I wnat to obtain something like that : ... (2 Replies)
Discussion started by: lsaas
2 Replies

8. Shell Programming and Scripting

Bash Copy-Move file problem

Hello, I made a script to copy files from one directory to another and move file after the copy is done. When files are present in the source directory there is no problem but when no file are present I'm getting an error. Please help !! --------------------- #!/bin/bash ... (2 Replies)
Discussion started by: lsimoneau
2 Replies

9. Windows & DOS: Issues & Discussions

VNC copy paste problem

Hi, Am unable to cut & paste between the VNC windows client and local Windows machine. In few VNC windows client, i was able to do. (2 Replies)
Discussion started by: param_it
2 Replies

10. UNIX for Dummies Questions & Answers

cut, copy + paste

Hi all! How do I cut, copy and paste under unix??? (2 Replies)
Discussion started by: aitor314
2 Replies
Login or Register to Ask a Question