Visit Our UNIX and Linux User Community


Problems with simple script in cygwin


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problems with simple script in cygwin
# 8  
Old 08-11-2009
Works fine on my PC with cygwin :
Code:
$ which bash
/usr/bin/bash
$ cat blianna.sh
#!/usr/bin/bash
echo -n "Enter your name and press [ENTER]: "
read var_name
echo "Your name is: $var_name"

$ blianna.sh
Enter your name and press [ENTER]: Jp
Your name is: Jp
$

- Verify the path for bash
- Run your script directly like me.

Jean-Pierre.
# 9  
Old 08-11-2009
Quote:
Originally Posted by blianna
I write the code on block notes and then in the shell bash I write : sh name_file.txt
Use a unix editor or try to convert the file with:

Code:
tr -d '\r' < dosfile > unixfile

# 10  
Old 08-11-2009
I agree with franklin52 without knowing about the editor called "block notes".
The script file could well be in MSDOS format where each line is terminated with carriage-return/linefeed when unix expects each line to be terminated with just linefeed. This will upsed the shell interpreter.

franklin52 post is suggesting conversion of the script from MSDOS to unix format. This is a good suggestion.

If this doesn't work, try creating a script file under a new name with your favourite unix editor (e.g. "vi") and cut/paste your post into that file.
Then make the script executable:
chmod 755 scriptname
Then execute the script from the current directory:
./scriptname

Good luck.
# 11  
Old 08-15-2009
If you like to use your script/rule with some program then use it. If you like to run it using bash, then use it, not sh:
Code:
bash scriptname

or make your script executable as methyl has written and run it. In this case caller shell read the first line, find your programpath (/usr/bin/bash), start it with this scriptfile, just like previous commandline example has written.
Code:
chmod a+rx scriptname
./scriptname


Previous Thread | Next Thread
Test Your Knowledge in Computers #201
Difficulty: Easy
Perl is implemented as a core interpreter, written in C, together with a large collection of modules, written in Perl and C.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

2. UNIX for Dummies Questions & Answers

Im having cygwin problems on windooze 64

I have installed ruby with cygwin according to these inst: w w w .sproutcore.com/install_win/#tab=advanced-install but at the last command: gem install sproutcore I'm getting a bunch of errors: $ gem install sproutcore Fetching: rack-1.3.2.gem (100%) Fetching:... (0 Replies)
Discussion started by: Sssssssssssslep
0 Replies

3. Shell Programming and Scripting

simple problems in awk

Dear All, I have the following awk script. #!/bin/bash sh stdev.cmd data.file | awk '{print $2}' > out.data read d < out.data echo $d awk '{print $1,$2- $f}' new > newz The script runs "stdev.cmd" and output a file "out.data" and the value of the... (2 Replies)
Discussion started by: Yacob_123
2 Replies

4. UNIX for Dummies Questions & Answers

Simple Problems to Solve!

Hi, I'm pretty poor at using UNIX but I'm learning. Please help me with these simple problems! Much appreciated! 1. I've changed my shell from bash to csh but I prefer bash. How do I change back? I've tried using chsh -s but it's not working! 2. I'm trying to download TopCat. I've done... (2 Replies)
Discussion started by: SimonWhite
2 Replies

5. Shell Programming and Scripting

Cygwin and simple script with if

I am having an issue with using cygwin (on Windows XP). My script errors on if -command. The script here works fine on Linux, but cygwin fails... #!/bin/sh if then echo "Test" fi The error -message: ./ShellTest.sh: line 4: syntax error near unexpected token `fi' ./ShellTest.sh:... (1 Reply)
Discussion started by: jussist
1 Replies

6. Windows & DOS: Issues & Discussions

Problems with batch files for Cygwin/rxvt

I'm trying to write batch scripts of the kind that start a Cygwin session in rxvt from the desktop, with the added feature that the session starts in a folder other than $HOME. I want to do this for two folders I use often. According to the manpage, rxvt has a "-cd" command. Therefore, at first... (4 Replies)
Discussion started by: SilversleevesX
4 Replies

7. UNIX for Dummies Questions & Answers

I'm having problems with a simple for loop on a newline

for i in `seq 1 10 ` ; do printf $i '\n'; done gives me this: 1234567891064mbarch ~ $ (output followed by bash prompt) :( I've tried so many ways to create a newline at the end. Does anyone have any ideas.. Thanks in advance. Sorry (7 Replies)
Discussion started by: 64mb
7 Replies

8. Shell Programming and Scripting

Problems using join for simple database lookup

I am trying to get a script working that will perform a simple database lookup using the join command. Here are the two files that I am trying to join: % cat lookup1.txt Number_1 Other_data_a Number_5 Other_data_b Number_8 Other_data_c Number_10 Other_data_d % cat... (2 Replies)
Discussion started by: JasonHamm
2 Replies

9. UNIX for Dummies Questions & Answers

tip: Simple script won't run in cygwin - vim editor involved

I ran into this issue and thanks to various postings in various forums, was able to figure out the solution but didn't see one posting that laid the whole issue out cleanly. So thought the following might help others ... ------------------------------------------------------------------------... (2 Replies)
Discussion started by: oxysep
2 Replies

10. UNIX for Dummies Questions & Answers

A beginner for cygwin simple question

the current pwd is: c:\cygwin\home\hui which command can go to c:\documents and setting\hui\my documents\hui\reply.txt (1 Reply)
Discussion started by: zhshqzyc
1 Replies

Featured Tech Videos