How to use alias for opening file from its absolute path in csh - alias

I want to create an alias, which will take file name, get its path and open it by gvim.
Something like this:
alias gg "gvim `which \`"
usage:
> gg some_file_in_remote_path
But I cannot make it work in csh.
Can someone help please

The command "which" gets a full path of of shell commands.
It does not find the full path of of every file you have in your system.
The command you are looking for is "find", although searching the entire file system could be time consuming. Perhaps install "locate" and use that instead of find. Even then you would have to decide in your script what to do when multiple files have the same name.

Related

is there a way to use the full file path in the command line without typing it?

For example, I want to open a PDF file in the browser from the command line (just because it's much faster and I need to open many files at once) and when I use the command start [file name] from its directory it try to open it as a executable, so I need to open the browser and type the full path of the file as an attribute, is there a way to call the full path without typing it?
what I exactly need is I need the full path of a file to convert it to string (for example in the browser)
Using tab completions may help. For example, if your target file is named thisPDFisTotallyBananas.pdf and you have another file in the same folder named thisOtherPDFisNot.pdf, you could type thisP then TAB to complete the file name in the command prompt without needing to type the whole filename.

How does the path environment variable work?

I know how to add values to the path variable, so my question is not how to use it.
Rather, I want to know how it works under the hood. When you type in the name of a program to execute, how does the system make use of PATH to find the matching program? How does it know when it finds a match?
for example...
when you set c:\python27\ into your environment path...
and you goto cmd, you are at c:\ and you type python
cmd knows to check the environment path which it will find c:\python27\ among others. then it looks for the command in each path listed in your environment paths
then executes the command if it finds it
simply the env path tells where to look for the command if it is not in the current directory

Check if Windows batch variable starts with a specific string

How can I find out (with Windows a batch command), if, for example, a variable starts with ABC?
I know that I can search for variables if I know the whole content (if "%variable%"=="abc"), but I want that it only looks after the beginning.
I also need it to find out where the batch file is located, so if there is a other command that reveals the file's location, please let me know.
Use the variable substring syntax:
IF "%variable:~0,3%"=="ABC" [...]
If you need the path to the batch file without the batch file name, you can use the variable:
%~dp0
Syntax for this is explained in the help for the for command, although this variable syntax extends beyond just the for command syntax.
to find batch file location use %0 (gives full patch to current batch file) or %CD% variable which gives local directory

How do i read and write from/to a file in another directory?

I am trying to make a program that will write data to a file for another program to be able to read the data from it. The problem is that I can't figure out a way to do this when the file i am reading and writing from is in another directory than both of my programs. I know there are other ways of doing this, but I just thought that it would be useful to know how to do it. Anyone that can help me?
You can use the full path, e.g
local f1 = io.open('D:/test/b.txt') -- Windows
local f2 = io.open('/test/b.txt') -- Unix
or use relative path, e.g
local f = io.open('../../test/b.txt')
In this example, the file is in the test directory of the parent directory (..) of parent directory.

batch scripting: how to get parent dir name without full path?

I'm working on a script that processes a folder and there is always one file in it I need to rename. The new name should be the parent directory name. How do I get this in a batch file? The full path to the dir is known.
It is not very clear how the script is supposed to become acquainted with the path in question, but the following example should at least give you an idea of how to proceed:
FOR %%D IN ("%CD%") DO SET "DirName=%%~nxD"
ECHO %DirName%
This script gets the path from the CD variable and extracts the name only from it to DirName.
You can use basename command:
FULLPATH=/the/full/path/is/known
JUSTTHENAME=$(basename "$FULLPATH")
You can use built-in bash tricks:
FULLPATH=/the/full/path/is/known
JUSTTHENAME=${FULLPATH##*/}
Explanations:
first # means 'remove the pattern from the begining'
second # means 'remove the longer possible pattern'
*/ is the pattern
Using built-in bash avoid to call an external command (i.e. basename) therefore this optimises you script. However the script is less portable.