Using BASH on windows


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using BASH on windows
# 8  
Old 07-24-2013
[EDIT] I forgot to add the other stuff, such as what happens when I run my command line argument program. Here it is:

Quote:
t@The-Devver /cygdrive/c/Users/t/Desktop/MadExperiments
$ ./CommandParam.exe

No arguments found!
t@The-Devver /cygdrive/c/Users/t/Desktop/MadExperiments
$ ./CommandParam.exe These are arguments!

Filename: C:\Users\t\Desktop\MadExperiments\CommandParam.exe has 4 arguments.The arguments are:
Argument 0 is: (null)
Argument 1 is: (null)
Argument 2 is: (null)
Argument 3 is: (null)

t@The-Devver /cygdrive/c/Users/t/Desktop/MadExperiments
$ cat clineexperiment.c //CommandParam.exe is the name I gave my executable. clineexperiment is the name of the c file.
#include<stdio.h>

int main ( int argc, char *argv[] )
{

if ( argc > 1 ) {
printf( "Filename: %s has %d arguments.", argv[0], argc );
} else {
printf ("No arguments found!");
getchar();
return 0;
}


printf( "The arguments are: \n" );
for (long long int i = 0; i < argc; i++) {
printf( "Argument %d is: %s \n", i, argv[i] );
}


getchar();
return 0;
}


t@The-Devver /cygdrive/c/Users/t/Desktop/MadExperiments
$
OH yeah and I did not know the cygwin terminal was by default the bash terminal as well. So I was trying to use the bash application in place of the cygwin terminal. That may have been part of the problem. [/EDIT]

OK I've done all of that and here is what I got:
Quote:
t@The-Devver /cygdrive/c/Users/t/Desktop/madexperiments
$ ls
batchexample.bat CommandParam.exe hworld.exe test_foo.exe
char_array.c FunctionExperiment1 MadCExperiment test_function.c
char_array.exe Hallo.c NewlineToASCII.c test_function.exe
char_array2.c Hello.c.rtf NLToASCII.exe Text.rtf
char_array2.exe HelloWorld.c test.cpp
cLineExperiment.c HelloWorld.exe test.exe
CommandParam HelloWorld.o test_foo.c

t@The-Devver /cygdrive/c/Users/t/Desktop/madexperiments
$ cat cLineExperiment.c
#include<stdio.h>

int main ( int argc, char *argv[] )
{

if ( argc > 1 ) {
printf( "Filename: %s has %d arguments.", argv[0], argc );
} else {
printf ("No arguments found!");
getchar();
return 0;
}


printf( "The arguments are: \n" );
for (long long int i = 0; i < argc; i++) {
printf( "Argument %d is: %s \n", i, argv[i] );
}


getchar();
return 0;
}
t@The-Devver /cygdrive/c/Users/t/Desktop/madexperiments
$
The file I tried to run with bash is CommandParam.exe. All of these files were written in C. They were compiled using extra debugging options with GCC. Side note: GCC, some windows command prompt, and GDB are about the only command line experience I've had. Learning all of this was quite recent. I use this compiler and debugger because I've found they have much better debugging options than say MS Visual Studio Express (and they're free!). MS limits the debugging tools to certain compilers while leaving them out of the other packages.

Most of your guesses were correct. Entering cat just made the terminal echo whatever else I put in.

Last edited by Cambria; 07-24-2013 at 12:25 PM..
# 9  
Old 07-24-2013
Your shell could not find ls, et al, because they weren't installed. To repeat:
Quote:
Originally Posted by Corona688
Lesson #2: BASH is a shell. It excels at calling other programs but most things you use in it, like cp mv ls awk sed cut, are not built into it. (busybox is a huge exception here -- it DOES have all of these and hundreds more built in for your convenience.) Things you can expect to be builtins include echo, printf, and test.
If you want all these commands without having to install them, I suggest busybox again...


As for your program, you should not be using long long int unless you actually need a long long int. It is a 64-bit number -- printf %d expects a 32-bit one.

The %d reads the first 32-bits of your 64-bit number. The %s reads the other half as all-zeroes since it is all-zeroes, which becomes (NULL) when printed. The string itself never gets used.

Last edited by Corona688; 07-24-2013 at 01:00 PM..
This User Gave Thanks to Corona688 For This Post:
# 10  
Old 07-24-2013
What would tell me my computer was messed up if I had installed cygwin to the wrong place on my drive? Because I got cygwin confused with MinGW, I installed cygwin to the C: drive, then my cygwin terminal on my desktop did not show the original icon that it had. Now the same command entered twice produces different results in cygwin BASH... is there any way to fix this?

I know it was a really stupid move to install it there. FYI I reinstalled cygwin to a folder on the C: drive which is called "cygwin" but the actual installation directory exists inside of that folder. I thought this would avoid the problem if it hadn't already happened. I didn't know where else to place it...
# 11  
Old 07-25-2013
Which command gives what different results? Always be specific! Please don't turn your thread into a game of 20 questions.

Removing then reinstalling everything in its proper locations may or may not fix the problem depending on what it is.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Windows Batch to Bash

This line is called in a windows batch file and I need to call the same 3 jars with Parms in a bash script. cd "D:\ACDRIP\JARS" java -cp ".\RIPError.jar;.\RIP31.jar;.\RIP31msg_en_US.jar" ResubmitErrors -Ahost -P185050 pause Any ideas how to do this in Bash? (3 Replies)
Discussion started by: xgringo
3 Replies

2. Shell Programming and Scripting

Windows Task with Bash script

Hello I have a problem with use bash script in windows task. If I use script by cygwin it's working well. If I use it by Windows task I'm get error Error : ERROR 2 (HY000) at line 2: File '.\xxx.csv' not found (Errcode: 2) Code Line : load data local infile './xxx.csv' REPLACE into... (16 Replies)
Discussion started by: karp
16 Replies

3. Windows & DOS: Issues & Discussions

Run Bash from Windows icon?

Is it possible to run a bash using a by creating an icon or shortcut in windows 7? Everything seems to be for unix or linux and unfortunately my institution is windows. For example, run bash ~/newbatch.sh by clicking on an icon on a users desktop. Cygwin will be installed as well. Thank you... (8 Replies)
Discussion started by: cmccabe
8 Replies

4. Shell Programming and Scripting

How to start powershell with shebang from windows/cygwin/bash?

I would like to the the windws8/cygwin/bash shebang feature to start a powershell script. I do a "chmod +x set-sound.ps1" and then at a bash prompt I do ./set-sound.ps1 The first line of ./set-sound.ps1 #!powershell.exe -ExecutionPolicy unrestricted The result is the result: ... (5 Replies)
Discussion started by: siegfried
5 Replies

5. Shell Programming and Scripting

File descriptors -- cygwyn bash (windows)

Cygwin bash script was invoked in bash shell as follows: /cygdrive/c/cygwin/bin/bash test.sh This is content of my script #!/bin/bash # exec 3</cygdrive/c/cygwin/home/work/part1.txt read -u 3 x echo $x exec 3<&- Commands work correctly when issued one at a time within bash shell.... (2 Replies)
Discussion started by: joed270
2 Replies

6. Shell Programming and Scripting

How to run Cygwin bash from windows scheduled task?

Hmmm.... I love these forums because I always get great prompt responses and I want to ask a question about running bash on windows. Is that allowed? Now I know I can install cygwin cron and run bash that way. Can I run bash from windows schedule task? How? thanks siegfried (1 Reply)
Discussion started by: siegfried
1 Replies

7. Shell Programming and Scripting

Windows to Unix? Using bash

Im posting here as i posted this in the wrong section before, sorry about that. Ok, im doing a self teaching course, im trying to understand how unix works, get and understand the basics before i hit the advance level. Now i have this in windows, Btw im always new at windows so correct me if... (9 Replies)
Discussion started by: newbie987
9 Replies

8. Shell Programming and Scripting

Writing Bash shell scripts corresponding to windows bat files

Experts, I am newbie in shell scripting. I want to write Bash shell scripts corresponding to windows bat files. I have installed cygwin at c:\cygwin and i am trying to crate the sh file using vi editor. i am not able to understand how to use linux/unix convention for the code. following is my... (15 Replies)
Discussion started by: rajuchacha007
15 Replies

9. Shell Programming and Scripting

Create Bash shell scripts corresponding to windows bat files

Experts, I am newbie in shell scripting. I want to write Bash shell scripts corresponding to windows bat files. I have installed cygwin at c:\cygwin and i am trying to crate the sh file using vi editor. i am not able to understand how to use linux/unix convention for the code. following is my... (1 Reply)
Discussion started by: rajuchacha007
1 Replies
Login or Register to Ask a Question