Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    26
    Rep Power
    0

    Editor in cygwin


    Hi, I had just installed cygwin on my win xp machine, new to unix & learning things...1. how can i know which editor had been installed with cygwin installation on my system? none of the editors out of vi, vim, nano, ted, jow etc working...tried using 'notepad' but it saves the file as .txt ....

    2. Also another confusion which i have is, even the files which i have created without shebang line as well as without .sh extension , I am able to execute them when given permission to do so...how can a script be run when i have not added shebang line in that? new to shell scripting, please help

    Thanks..
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,449
    Rep Power
    1751
    Not sure about which editors you'd have.

    As for the execution ... if you do not have a shebang lien the file, if executable, will be processed by your current shell.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    26
    Rep Power
    0
    Originally Posted by SimonJM
    Not sure about which editors you'd have.

    As for the execution ... if you do not have a shebang lien the file, if executable, will be processed by your current shell.



    Okay thanks, & it will get executed even if file doesn't have that particular shell's extension in its name too? i mean am using bash shell & am able to execute a file without .sh extension & shebang line...

    Also kindly make me understand this too...in my cygwin, i wrote comamnd 'notepad' & a notepad opened up, i wrote some script in that notepad & saved it as 'name.sh' through my computer-> C: -> cygwin -> home -> user , & obviously it gets saved as 'name.sh.txt' so shouldn't i be able to execute this 'name.sh.txt' too since any script is also a text file...?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,449
    Rep Power
    1751
    The extent does not matter a jot in *nix. You can have a text file called explorer.exe and a binary program called fred.txt. It's what you try and do with them that matters.
    If you are running a bash shell then any executable (assuming it is a shell script) will run within that bash shell (using a copy of your current environment).
    What makes a file executable (text/shell, biney command, etc.) is the attributes it has. If you do a ls -l name.sh.txt (in the directory where the file is, of course!) you will see a row of characters to the left of the screen, possibly looking like: -rwxrx-r--
    The first (leftmost) - indicates a 'normal' file (not a directory or soft link, etc.), followed by three groups of three characters which denote persmissions/attributes and are read, write, execute indicators for the owner of the file, the group (by default the primary group that the creator belongs to), and everyone. Taking the example above, the first 3 characters are rwx which means the owner of the file can read, write (also delete) and execute the file.
    Beyond that, the system must be able to find the file. It just being in the current directory may not be enough, as *nix system use a variable called PATH to determine where to look for things when just a name use used.

    Comments on this post

    • Amukherji agrees
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    26
    Rep Power
    0
    Originally Posted by SimonJM
    The extent does not matter a jot in *nix. You can have a text file called explorer.exe and a binary program called fred.txt. It's what you try and do with them that matters.
    If you are running a bash shell then any executable (assuming it is a shell script) will run within that bash shell (using a copy of your current environment).
    What makes a file executable (text/shell, biney command, etc.) is the attributes it has. If you do a ls -l name.sh.txt (in the directory where the file is, of course!) you will see a row of characters to the left of the screen, possibly looking like: -rwxrx-r--
    The first (leftmost) - indicates a 'normal' file (not a directory or soft link, etc.), followed by three groups of three characters which denote persmissions/attributes and are read, write, execute indicators for the owner of the file, the group (by default the primary group that the creator belongs to), and everyone. Taking the example above, the first 3 characters are rwx which means the owner of the file can read, write (also delete) and execute the file.
    Beyond that, the system must be able to find the file. It just being in the current directory may not be enough, as *nix system use a variable called PATH to determine where to look for things when just a name use used.

    Thanks agn for making me understand this , one last thing i wanted to confirm is , whther 'notepad' is an accepted editor to be used in cygwin? , since i searched thru internet n cygwin site & there is no mention of 'notepad' command & thus notepad editor to be used with cygwin..when am using this 'notepad' command & played around with it, i got that only issue is i need not put any blank line between line of codes in notepad editor, no blank line even after that shebang line, since notepad is actually windows based & thus it uses CL-RF line endings & unix uses only \n line endings..so if i give blank line between line of code in the script which i wrote in notepad editor,& execute that, it outputs,' .../r command not found', rest of output is okay.....so better i install any editor or should use this notepad command for this purpose....

    Also, if a file is in current directory, wouldn't the system be able to find the file always? can u also explain last 2 lines of ur reply, just wanted to make sure i understud
    thnxx lots for ur help..
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,449
    Rep Power
    1751
    You are quite correct about line-endings between native *nix and windows files. I have never used Cygwin and know only a very little about it, so this will be a guess ... I am guessing that when you use notepad it is invoking the windows binary (as Cygwin runs in the native windows environment to give a *nix-like 'shell' (to use a phrase!)) in which case it will, when saving, use carriage-return and linefeed characters as end of line markers. If you have access to a dos2unix command in Cygwin that should be able to correct those. I would have thought you might have vi available 'natively', but you mentioned they do not work - is that because they are not available or that they generate errors?

    Back to the PATH situation ... it is often deemed insecure (especially for root accounts) to have the current directory (specified as .) in the PATH as that can be used to 'fool' people into running a different command to the expected system one. If you type:
    Code:
    echo $PATH
    you should see a list of directories, delimited by colons. When you type in just a filename, the system assumes you wish to execute a file with that name and will search for it for you. It will look in each directory in turn, from left to right, that is included in the PATH. If the current directory is not included (either specified in full for just this directory, or as . to mean the current directory regardless of where you are) then the file will not be found.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    26
    Rep Power
    0
    Originally Posted by SimonJM
    You are quite correct about line-endings between native *nix and windows files. I have never used Cygwin and know only a very little about it, so this will be a guess ... I am guessing that when you use notepad it is invoking the windows binary (as Cygwin runs in the native windows environment to give a *nix-like 'shell' (to use a phrase!)) in which case it will, when saving, use carriage-return and linefeed characters as end of line markers. If you have access to a dos2unix command in Cygwin that should be able to correct those. I would have thought you might have vi available 'natively', but you mentioned they do not work - is that because they are not available or that they generate errors?

    Back to the PATH situation ... it is often deemed insecure (especially for root accounts) to have the current directory (specified as .) in the PATH as that can be used to 'fool' people into running a different command to the expected system one. If you type:
    Code:
    echo $PATH
    you should see a list of directories, delimited by colons. When you type in just a filename, the system assumes you wish to execute a file with that name and will search for it for you. It will look in each directory in turn, from left to right, that is included in the PATH. If the current directory is not included (either specified in full for just this directory, or as . to mean the current directory regardless of where you are) then the file will not be found.



    oh okay thanks....understood abt why current directry nt included in path..if wud hv any doubt will ask u agn , n yes when i installed Cygwin, initially it installs default basic packages, so no editor was installed, went to cygwin site & as directed there, ran setup.exe again to update, hv now installed vim & sed as editors, thr was sum error in installing sed so wud use vim now..learning shell scripting online bt sometimes there's conflicting info on different sites,wud need to hv a look at any book later i think,nt now....neways, thanks a lot for ur help
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,449
    Rep Power
    1751
    vim (a slightyl more friendly version of vi) is a decent enough editor once you get used to it, sed is generally used for 'batch edits' so don't worry too much about that.

    If you have any questions don't hesitate to ask - starting a new thread for each question is a good idea.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    26
    Rep Power
    0
    Originally Posted by SimonJM
    vim (a slightyl more friendly version of vi) is a decent enough editor once you get used to it, sed is generally used for 'batch edits' so don't worry too much about that.

    If you have any questions don't hesitate to ask - starting a new thread for each question is a good idea.


    Sure, thanks for help !
  18. #10
  19. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2006
    Posts
    857
    Rep Power
    388

    Wink


    Originally Posted by Amukherji
    ...tried using 'notepad' but it saves the file as .txt ....
    Cygwin does not come with any editor and therefore defaults to "notepad".
    Unfortunately notepad will save the edited file with CR_LF at the end of each line and cygwin will give error if you try to execute that file.
    An alternative is to download TextPad which you can configure to replace notepad and also save files in Unix format (LF only at end of each line).
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    26
    Rep Power
    0

    Question


    Originally Posted by LKBrwn_DBA
    Cygwin does not come with any editor and therefore defaults to "notepad".
    Unfortunately notepad will save the edited file with CR_LF at the end of each line and cygwin will give error if you try to execute that file.
    An alternative is to download TextPad which you can configure to replace notepad and also save files in Unix format (LF only at end of each line).
    Yes bt it only gives error when there is any blank line between any two lines of code in that notepad..if i dont give any blank line then all commands in script gets executed fine....so why carriage return is not recognized(& thus error) by unix when i dont give any blank line..unix recognizes only \n &thus gives error when it encounters notepad's \r(carriage return)....but its happenign only when there is blank line , & when no blank line,next command of notepad gets executed fine...why?...though i hv downloaded an editor now for cygwin & working in that forgetting notepad or this confusion
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,449
    Rep Power
    1751
    Not sure about Cygwin, but a few flavours of *nix give a 'bland' and very confusing "file not executable" style error message when they come across this sort of thing. If you look at the file so created with a 'proper' editor within *nix you should see ^M characters at line ends, and it is those that need to be removed.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    26
    Rep Power
    0
    Originally Posted by SimonJM
    Not sure about Cygwin, but a few flavours of *nix give a 'bland' and very confusing "file not executable" style error message when they come across this sort of thing. If you look at the file so created with a 'proper' editor within *nix you should see ^M characters at line ends, and it is those that need to be removed.

    okay, but when when am using 'vim', proper editor of unix then there is no error etc. I was talking abt notepad as 'lkbrown dba', the previous poster talked abt line endings in notepad. Only when there are blank lines in script written in notepad, its execution gives error, else notepad script also runs fine.

    2 examples when i used 'notepad' command to open notepad :-

    test.sh

    #!/bin/sh
    echo hi this is me
    echo where were you

    gives o/p

    hi this is me
    where were you

    &

    tetsing1.sh

    #!/bin/sh

    echo hi this is me

    echo where were you


    gives o/p

    $ ./tetsing1.sh
    ./tetsing1.sh: line 2: $'\r': command not found
    hi this is me
    ./tetsing1.sh: line 4: $'\r': command not found
    where were you




    so, only second script is not recognising \r & giving error, whereas first script also shouldnot have recognised \r since unix recognises only \n line endings...so ideally both the scripts should have given error or none of the scripts should have given any error.

    although am nt thinking abt notepad now as with 'vim evrything is fine

    thanks again for your reply
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,449
    Rep Power
    1751
    That just looks to be a 'quirk'/bonus of how Cygwin's native shell handles blank lines in scripts. Normally (in 'real' *nix systems), a script created/saved in a Windows text editor would not run at all.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    26
    Rep Power
    0
    Originally Posted by SimonJM
    That just looks to be a 'quirk'/bonus of how Cygwin's native shell handles blank lines in scripts. Normally (in 'real' *nix systems), a script created/saved in a Windows text editor would not run at all.

    yes n u right abt it being quirk too ,even i didn't expect that notepad script would get executed, but since cygwin is just an emulator of unix on windows operating system, so might be cygwin has this functionality, cygwin preferably needs to be installed in C drive of one's system, & to access our windows components through cygwin we need to do /cygdrive/C i think, installed it to run shell scripting but now nt getting time to practice it, donno when i'll start it again
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo