Pb with spaces in .bashrc ALIAS - cygwin

I have exactly the same pb :
Spaces in Cygwin/bash aliases?
i'm using rxvt in bash mode and i'm trying to setup my alias in the .bashrc
If i follow the answer of the previous post my alias look like this:
alias ma="/cygdrive/c/Program\ Files/Autodesk/Maya2011/bin/maya.exe"
but i get this :
$ ma
: No such file or directoryiles/Autodesk/Maya2011/bin/maya.exe
i also try this synthax :
alias ma="/cygdrive/c/Program Files/Autodesk/Maya2011/bin/maya.exe"
but it give me
$ ma
bash: /cygdrive/c/Program: No such file or directory
So if you guys have any idea on how to solve this, it would be great !
Cheers
sk
PS : i Edit my question because i'm not allowed to answer my own question
Thanks for your help guys !
i try to replace with the Progra~1 synthax and it doesn't work. So i was wondering if the pb comes from the space character.
so i try to create an alias to an .exe that doesn't need space character:
alias py1="/cygdrive/c/Python27/python.exe"
alias py2='/cygdrive/c/Python27/python.exe'
alias py3=/cygdrive/c/Python27/python.exe
alias py4='cd /cygdrive/c/Python27'
and i also get an error
$ py1
: No such file or directorypython.exe
$ py2
: No such file or directorypython.exe
$ py3
: No such file or directorypython.exe
$ py4
: No such file or directoryn27
so i wonder if the cygwin synthax for creating Alias is the same than the Linux one ?
or maybe there is something wrong with windows 7 x64 ? i really don't know where the problem come from ?

Two possible workarounds:
Replace Program Files in your path with Progra~1, or
Make a symlink to remove spaces: mklink /D c:\programs "c:\Program Files" (afair, mklink is only present starting from Vista)

Use an advanced editor like the free Notepad++ to modify the not DOS format .bashrc file. Don't use Microsoft's Notepad becouse interprets CRLF as a newline. While on Mac/Unix newline is just LF. if you have mistakenly converted and saved the file, you can find a copy of the original in cygwin\etc\skel.
To show the End of Line symbol used in a file, in Notepad++ use View -> Show Symbol -> Show End of Line.

The easier solution is to move Autodesk directory from C:\Program Files\ to C:\

+1 for file type to save .bashrc, .profile etc. with Cygwin: for example with TextPad be sure to select file type Unix on Save. Without it .... all sorts of bizareness.

well i reinstall cygwin and things are now going better
when i only put this
alias wp="/cygdrive/c/Program\ Files/Windows\ NT/Accessories/wordpad.exe"
it now works ! but when i enter this
alias wp="/cygdrive/c/Program\ Files/Windows\ NT/Accessories/wordpad.exe"
alias nk="/cygdrive/c/Program\ Files/Nuke6.2v1/Nuke6.2.exe"
the wp give me an error
$ wp
: No such file or directoryiles/Windows NT/Accessories/wordpad.exe
but the nk alias works
so i figure that the problem was coming from the carriage return character created by notepad, i try this :
alias wp="/cygdrive/c/Program\ Files/Windows\ NT/Accessories/wordpad.exe" nk="/cygdrive/c/Program\ Files/Nuke6.2v1/Nuke6.2.exe" ma="/cygdrive/c/Program\ Files/Autodesk/Maya2011/bin/maya.exe"
and it works perfectly !
so in my case the pb is i guess the carriage return created in notepad, it may create an hidden character that cygwin doesn't like. i'll try to edit my .bashrc in vi directly in order to see if the pb come from notepad or directly from carriage return.
it would be interesting if you check that if this syntax works on your computer
alias myalias1="/cygdrive/c/.../pgm1.exe"
alias myalias2="/cygdrive/c/.../pgm2.exe"
alias myalias3="/cygdrive/c/.../pgm3.exe"
thanks again for your support !
cheers !

Related

How to open a "-" dashed filename using terminal?

I tried gedit, nano, vi, leafpad and other text editors , it won't open, I tried cat and other file looking commands, and I ensure you it's a file not a directory!
This type of approach has a lot of misunderstanding because using - as an argument refers to STDIN/STDOUT i.e dev/stdin or dev/stdout .So if you want to open this type of file you have to specify the full location of the file such as ./- .For eg. , if you want to see what is in that file use cat ./-
Both cat < - and ./- command will give you the output
you can use redirection
cat < -file_name
It looks like the rev command doesn't treat - as a special character.
From the man page
The rev utility copies the specified files to standard output, reversing the order of characters in every line.
so
rev - | rev
should show what's in the file in the correct order.
I tried with pico or vi command.pico readme which allowed me open in editor and read the contents.
if you want to open this type of file you have to specify the full location of the file such as ./- .For eg. , if you want to see what is in that file use cat ./-
cat ./- is the syntax that reveals the correct password for bandit the "rev -" reveals something else

Renaming files like 20141207_190822.jpg to "2014-12-07 19.08.22.jpg" in linux or MacOS X

How in Linux or MacOS X to rename a bunch of files with names 20141207_190822.jpg and 20141207_190823.mp4 to this format:
2014-12-07 19.08.22.jpg
and
2014-12-07 19.08.23.mp4
?
I've found many examples how to just add something to the beginning of filename, but here I need to change the mask by inserting symbols in the middle of filenames and replacing _ with space " ".
Thank you
Try doing this :
$ rename 's#^(\d{4})(\d{2})(\d{2})_(\d{2})(\d{2})(\d{2})#$1-$2-$3 $4.$5.$6#' *
There are other tools with the same name which may or may not be able to do this, so be careful.
If you run the following command :
$ file $(readlink -f $(type -p rename))
and you have a result like
.../rename: Perl script, ASCII text executable
then this seems to be the right tool =)
If you don't have this command, search your package manager to install it or do it manually
Last but not least, this tool was originally written by Larry Wall, the Perl's dad.

Bash profile alias giving unexpected EOF and syntax errors

I'm trying to add the following alias in my .bash_profile in TextEdit in Mavericks (10.9.3) on a Mac Mini:
alias proj="cd ~/documents/google\ drive/web/projects"
I get the following errors:
line 1: unexpected EOF while looking for matching '"'
line 2: syntax error: unexpected end of file
bash gives:
alias proj='"cd'
However, if I copy & paste the exact same line from Notepad in my Windows VM into TextEdit it works..
bash now gives as expected:
alias proj='cd ~/documents/google\ drive/web/projects'
I've tried the following with no success:
Different paths with and without spaces
Swapped the Dell PC keyboard I was using for a Mac
Changed language to British English from British
Installed all updates
I can get round it using copy & paste as above, but would really like to get to the bottom of it. Any ideas much appreciated, thanks.
It is a quoting problem. Try:
alias proj="cd ~/documents/'google drive'/web/projects"
when eval-ing the alias command, the double quotes are removed.
When processing the "proj" invocation, the single quotes are removed.
Your original backslash was removed at alias evaluation time.
You could also double the backslashes:
alias proj="cd ~/documents/google\\ drive/web/projects"
Works for me. Turn on command tracing (set -x) and see what really happens.
$ cat xx ; source xx ; proj ; pwd
alias proj="cd $HOME/workspace/'google drive'/web"
/home/sciadmin/workspace/google drive/web
P.S. I sanity checked the equivalence of "$HOME" and "~" as an alias. Works fine, so replacing $HOME with ~ will work in the above example.
OK, here's the results for a symlink:
$ . xx ; cat xx ; proj ; pwd ; pwd -P
alias proj="cd ~/workspace/'google drive'/web"
/home/sciadmin/workspace/google drive/web
/home/sciadmin/workspace/foo bar/web
I think you may not be using BASH.
I had some issues with textedit and bash. Check textedit preferences 'GENERAL' and select plain text, then turn off smart quotes and smart dash.
If that doesn't do it - then, sadly, I am Sans Clue.

syntax error near unexpected token ' - bash

I have a written a sample script on my Mac
#!/bin/bash
test() {
echo "Example"
}
test
exit 0
and this works fine by displaying Example
When I run this script on a RedHat machine, it says
syntax error near unexpected token '
I checked that bash is available using
cat /etc/shells
which bash shows /bin/bash
Did anyone come across the same issue ?
Thanks in advance !
It could be a file encoding issue.
I have encountered file type encoding issues when working on files between different operating systems and editors - in my case particularly between Linux and Windows systems.
I suggest checking your file's encoding to make sure it is suitable for the target linux environment. I guess an encoding issue is less likely given you are using a MAC than if you had used a Windows text editor, however I think file encoding is still worth considering.
--- EDIT (Add an actual solution as recommended by #Potatoswatter)
To demonstrate how file type encoding could be this issue, I copy/pasted your example script into Notepad in Windows (I don't have access to a Mac), then copied it to a linux machine and ran it:
jdt#cookielin01:~/windows> sh ./originalfile
./originalfile: line 2: syntax error near unexpected token `$'{\r''
'/originalfile: line 2: `test() {
In this case, Notepad saved the file with carriage returns and linefeeds, causing the error shown above. The \r indicates a carriage return (Linux systems terminate lines with linefeeds \n only).
On the linux machine, you could test this theory by running the following to strip carriage returns from the file, if they are present:
cat originalfile | tr -d "\r" > newfile
Then try to run the new file sh ./newfile . If this works, the issue was carriage returns as hidden characters.
Note: This is not an exact replication of your environment (I don't have access to a Mac), however it seems likely to me that the issue is that an editor, somewhere, saved carriage returns into the file.
--- /EDIT
To elaborate a little, operating systems and editors can have different file encoding defaults. Typically, applications and editors will influence the filetype encoding used, for instance, I think Microsoft Notepad and Notepad++ default to Windows-1252. There may be newline differences to consider too (In Windows environments, a carriage return and linefeed is often used to terminate lines in files, whilst in Linux and OSX, only a Linefeed is usually used).
A similar question and answer that references file encoding is here: bad character showing up in bash script execution
try something like
$ sudo apt-get install dos2unix
$ dos2unix offendingfile
Easy way to convert example.sh file to UNIX if you are working in Windows is to use NotePad++ (Edit>EOL Conversion>UNIX/OSX Format)
You can also set the default EOL in notepad++ (Settings>Preferences>New Document/Default Directory>select Unix/OSX under the Format box)
Thanks #jdt for your answer.
Following that, and since I keep having this issue with carriage return, I wrote that small script. Only run carriage_return and you'll be prompted for the file to "clean".
https://gist.github.com/kartonnade/44e9842ed15cf21a3700
alias carriage_return=remove_carriage_return
remove_carriage_return(){
# cygwin throws error like :
# syntax error near unexpected token `$'{\r''
# due to carriage return
# this function runs the following
# cat originalfile | tr -d "\r" > newfile
read -p "File to clean ? "
file_to_clean=$REPLY
temp_file_to_clean=$file_to_clean'_'
# file to clean => temporary clean file
remove_carriage_return_one='cat '$file_to_clean' | tr -d "\r" > '
remove_carriage_return_one=$remove_carriage_return_one$temp_file_to_clean
# temporary clean file => new clean file
remove_carriage_return_two='cat '$temp_file_to_clean' | tr -d "\r" > '
remove_carriage_return_two=$remove_carriage_return_two$file_to_clean
eval $remove_carriage_return_one
eval $remove_carriage_return_two
# remove temporary clean file
eval 'rm '$temp_file_to_clean
}
I want to add to the answer above is how to check if it is carriage return issue in Unix like environment (I tested in MacOS)
1) Using cat
cat -e my_file_name
If you see the lines ended with ^M$, then yes, it is the carriage return issue.
2) Find first line with carriage return character
grep -r $'\r' Grader.sh | head -1
3) Using vim
vim my_file_name
Then in vim, type
:set ff
If you see fileformat=dos, then the file is from a dos environment which contains a carriage return.
After finding out, you can use the above mentioned methods by other people to correct your file.
I had the same problem when i was working with armbian linux and Windows .
i was trying to coppy my codes from windows to armbian and when i run it this Error Pops Up. My problem Solved this way :
1- try to Coppy your files from windows using WinSCP .
2- make sure that your file name does not have () characters

Vim problem with gf command

I am using Vim and I have set the path (set path+= c:/work/etc/etc) to my project directory (for C#), but still using command 'gf' give me error:
E:447 Can't find file.
Is there anything I am doing wrong over here?
G'day,
To get a bit more detail on your current path settings you can see what's being included and the files vim can't find by entering the command:
:checkpath
and you'll get a dump of the files not found, e.g.
--- Included files not found in path ---
<io.h>
vim.h -->
<functions.h>
<clib/exec_protos.h>
Or you can get a listing of all included files, both found and not found, by entering
:checkpath!
Enter
:help path
to get more info on the path syntax.
Edit: Don't forget that using the syntax
set path=/work
will completely reset your path variable to what you've just declared. I'd suggest using
set path+=/work
instead. This won't clobber the current path and will just add your /work directory instead.
HTH
I also found out that
:set path+=./foo/bar
adds a search location relative to the directory of the current file, just like '.' does.
My vim didn't want to search for such include
#include <common/util/string.h>
So what I needed to do was
:set path+=foo/bar
instead of
:set path+=./foo/bar
The former adds a search path relative to current working directory. Hopefully it helps someone.
First can you open the file using :find file.name ? (:help find for more info). If this does not work then your path is wrong. If :find does locate your file then do the following:
Insure that you are not in Visual/Insert mode
Place cursor on the first letter of the filename and press gf
I know this is an old question, but I also had some troubles with this for another reason and it took me some time to find out why. I hope this might be helpful to someone.
When a directory is matched with wildignore, gf does not work for files in it, nor does :find.
This is obvious if you read wildignore's documentation, but I forgot I ever changed this variable, and what it was for exactly. Also I used a glob, and it was not immediately apparent to me that the directory I was using gf in, was also matched with this glob.
Make sure there is no leading character to the file name if you press gf, i.e. using gf when the cursor is on help.txt will not work here:
file=help.txt
If you are talking about the gf tool wri††en by tomnomnom then here's how to set-up:
Setting PATH for GO (if you have not setup yet).
export GOROOT=$HOME/go
export PATH=$PATH:$GOROOT/bin
Step 1: Download tool from github
Step 2: cp -r path/to/tomnomnom/gf/examples ~/.gf
Step 3: source ~/tools/gf/gf-completion.bash
Now gf should work along with auto-completion from anywhere.
Source: Original sources are present at his repo.

Resources