So I'm looking into using BASH on this windows 7 machine. I've installed cygwin with a few optional bash installations but I don't know how to get bash to "work". I've opened the .exe and typed what few commands I understand from the tutorials I've found but some of the commands do not work. I don't know why, though I suspect that the unix utilities must be missing because this is a windows machine.
echo works, as does cd, but many other commands do not. How could I also learn to use Bash? I'm command line dumb...
cygwin is indeed a good option. By default, cygwin does not install a lot of utilities by itself. Run setup again, and in the list of packages to be installed, search and select all those utilities that you want installed and complete the installation. This will update your cygwin with additional utilities that you selected.
You could get Busybox for Windows, which includes a Bourne shell and a huge assortment of shell utilities in one executable. Zero installs instead of 750.
But how come some of the commands don't work? I've never used Bash or any command line really. I only thought the reason they don't work was because I was looking up reasons why and I found some info which said that might be the case.
Could anyone possibly point out a good [complete] beginners tutorial for bash as well?
If I had to guess, it's because they're not installed, but that's a complete wild guess. Tell us what you did! Don't make us guess.
Lesson #1: BASH is an extended Bourne shell. There are many, many different Bourne shells with slightly different features. You can write scripts which only work in bash, scripts that work in only some versions of BASH, or scripts that work in any Bourne shell by choosing which features you use. Things like arrays and substring operators will not work in all shells.
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.
Last edited by Corona688; 07-23-2013 at 12:24 PM..
I was primarily concerned with the commands at the start of a tutorial which I was reading but had to stop because the commands were not working in BASH.
I tried ls, and cat but neither did anything.
One more thing, I tried running a program that I created which accepts command line arguments and prints them on screen. When I give it my argumeets in bash they always come up NULL, and there's only two of them when there are many more. I don't know why that is either...
...I tried ls, and cat but neither did anything. ...
Since you appear to be new here, I'd like to mention that the way to get the quickest responses is to actually cut and paste your commands and their responses from your terminal.
"xyz is not working" or "xyz does not do anything" are very vague statements; somewhat like calling your car mechanic and telling him "my car won't start". There could be a lot of reasons for that and the mechanic won't know what's wrong with your car unless he actually inspects it himself. It's the same thing over here.
In any case, here are the steps to install Cygwin from what I could remember; see if you followed them all.
(1) You have a working (non-corrupted) version of Windows and you downloaded setup.exe from the Cygwin website.
(2) If your computer is 32-bit, you downloaded the 32-bit version of setup.exe, or ditto for 64-bit.
(3) You double-clicked on setup.exe and clicked through the wizard to install Cygwin. In the final screen, it shows you an option to put up an icon on your Windows desktop. If you had checked that, you'd see the Cygwin icon on your desktop.
(4) Assuming that you do see the icon; if you double-click on it, the Cygwin shell would've opened up. By default, it is the Bash shell, and you'd see a "prompt". If you keep on pressing the "Enter" or "Return" key, you'd see the prompt printed repeatedly, because it is waiting for you to enter a command.
(5) Now, "ls" and "cat" are pretty basic commands, so they should be installed as a part of the core setup. If you've done everything till now as mentioned above, then run the following commands at your prompt:
and then
They should provide you some information about what "ls" and "cat" are in your system. Run those commands and paste their output over here.
(6) The "ls" command without any argument lists all the files (which includes directories in Unix/Linux) in the current directory. So if you are in an empty directory, "ls" won't print anything and you'll simply see your prompt printed in the next line. Maybe that's what you are confused about?
Try the following command:
This will print a long listing of all files, including hidden files, which in Unix/Linux are the ones that start with "." character. You should see atleast two lines printed. Post the output of this command over here.
(7) The "cat" command "concatenates" the contents of the files you pass as arguments.
- If you pass one argument, it will print the contents of that file.
- If you pass two arguments, it will print the contents of the two files one after the other. Ditto with more than two arguments.
- If you don't pass any arguments and press "Enter", it will simply wait for you to enter something. Once you enter something, it will simply echo your input.
Maybe that's what you saw?
Try this command:
If a file called "myfile" exists in your current directory, this command will print its contents. If it does not, it will show an appropriate error message. Cut and paste the output of that command over here.
Quote:
Originally Posted by Cambria
...
I tried running a program that I created which accepts command line arguments and prints them on screen. When I give it my argumeets in bash they always come up NULL, ...
Without knowing:
(a) what that program is
(b) what language it is written in
(c) how it was saved or compiled in your system
(d) how it was invoked by you
(e) how you passed the arguments to it
it is difficult to say why it came up with NULLs.
Let's say you saved your program in a file called "myfile". Then run the following command:
and paste its output over here.
And then copy and paste the command(s) you ran to invoke it and the response you received.
This User Gave Thanks to durden_tyler For This Post:
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)
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)
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)
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)
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)
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)
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)
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)
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)