Figure out the destination of `ln -s` using script - shell

First, here's the script I'm talking about:
https://github.com/Greduan/dotfiles/blob/master/scripts/symlinks.sh
Check line 20. It has the following content
dest = "$HOME/.`basename \"${source%.*}\"`"
Since I took this from another script, I have no idea what it actually does. I'm guessing what it does is if the source file is named vimrc.vim.symlink it'll output .vimrc.vim, correct?
If not correct, could you please explain what it does?
And could you please help me figure out how to make it so that if the file is vimrc.vim.symlink, how can I make it so that I can get .vimrc?
Please check the script so that you can understand what I'm talking about. :)

First of all, your analysis is correct. ${source%.*} removes the .* suffix from source. The rest, $HOME/.$(basename \"...\") takes the basename of source, which removes all path from it, leaving only the file name and is placed after $(HOME)/..
If you want to remove everything after (and including) the first dot, you can use ${source%%.*} (with %% instead of %). This answer gives you examples.

Related

Possible to copy/move/etc multiple files of same base name via Windows CMD/.BAT?

I am wondering if it is possible to accomplish the following, given some context and example.
I have files in "Server\Share\Folder\File##.ext"
Sometimes the "File##.ext" can be "File01.ext" through "File20.ext", and other times it may be "File01.ext" through "File40.ext"
Sometimes there are less of these files, sometimes there are more.
I want a batch file to take the files from "Server\Share\Folder\File##.ext" and move them to "Server\Share\OtherFolder\File##.ext". I know I can accomplish this easily with:
copy /y "Server\Share\Folder\File01.ext" "Server\Share\OtherFolder\File01.ext"
Then just add another line for each extra "File02.ext, File03.ext, etc., but I am wondering if it is possible to make it so that any file that resembles "File##.ext" can be included, so that no matter how many ## I have, it always works without issue.
Thanks in advance for any and all advice!
EDIT
Someone mentioned using Wildcards, but my question with that is - lets say those files are File01.ext through File05.ext, will it match what it finds to the newly moved file? Like will it find File01 from File?? on the source and Make it File01 from File?? at the destination?
You can accomplish this task with a FORloop program in batch-file.
You can also loop through the Commands using : and variable name.
Combining these two would help you get what you want.
We can help you with Ideas and little bit of the coding. But the Efforts must be done by you. So U can learn programming better

Read a filename while running and insert it (bash)

I'm new to bash so I need a lot of help for probably a little thing. I'll try to explain, what I want to do or where I need help. (Excuse my english if I make mistakes)
There is a Script, which creates a numbers of .gv Files. In those .gv Files are some commands to make a graph. With "dot" I'm gonna create a picture with that.
My code now is
dot -Tsvg *.gv -o ????.svg
I need help with those ???? - In the *.gv are all .gv listed (you know what I mean I guess...) anyway, the ????'s should have the same name as the file,but there are more than one file so I don't know how to code that. It just should take the Filename while it's running.
The -O option generates names for you, based on the input name and the output format.

Glob works on local machine fails to detect files in remote

I'm using glob to get a list of all the files inside the target directory. This works on my laptop but not on my server.
Here's my code:
my $dir = "c:/MyTargetDir";
#files = glob "$dir/*.*";
print $dir . "\n";
print $#files;
Results:
c:/MyTargetDir
0
I've already set the folder security settings to allow everyone's modification but it's still not working. What might be causing this?
UPDATE:
OK legit another case of noob assumptions here. Thought $#files would show the amount of object inside the array but it actually shows one less of the actual amount of objects, meant for the for (0..$#files) loop. The problem actually lies elsewhere but I assumed wrongly. Thanks for the inputs.
If MyTargetDir actually contains spaces, you need to use bsd_glob instead, which treats spaces as part of the file name.
use File::Glob ':bsd_glob';
#files = bsd_glob "$dir/*.*";
Otherwise, there is seemingly no problem with your code, and you may still have a permissions issue. You should check $! to see if you are getting an error.
If you want to simply get all files in a directory, readdir might be a better solution

LDAP Script Help - Put ldapserach command results in single quotes

The following script works, but I need help with one change. Right now using lday serach, and a little utility called GETPASS, this script will pull a listy users, from a specified context out of an LDAP directory, compare their LDAP password, to an unused attribute, If different, add it to the unused attribute called carLicense, and then send it in SHA 1 format, up our google APPS domain, with Google Apps directory sync. The one problem, is that it when it returns the ldapsearch, it works fine with a user in this format:
cn=joebloe,ou=googletest,o=someorg
However, if the usename has a space in it like this:
cn=joe bloe,ou=googletest,o=someorg
the script will fail as it does not know how to deal with that space. In this situations, a single quote, around the DN will solve the issue IE:
'cn=joe blow,ou=googletest,o=someorg'
However, I have tried to alter the script to address this need of mine, and I am failing miserably, please see a copy of the script in Pasetebin below. Any help with be deeply and GREATLY appreciated, as this is currently my only stumbling block to success.
http://pastebin.com/htWxsNXj
Replace the first line of generating result file (in your pasting is line 66) with:
echo "dn: '$RESULT'" >> $SCRIPTPATH/gadspwsync.ldif
If it won't help, don't remove the file in line 75. Check the content, show us the first line, then show the expected content.

Find completely commented files

In a solution with lots of files and projects - how would you find all completely commented files? I assume that every line of code starts with // (EDIT: or is empty) in such files.
I am using VS 2008, C#, ReSharper is available.
I know, normally such files should not exist - that's what a source safe is for ...
To find all files in and under the current directory in which all lines begin with '//':
find . -type f -exec sh -c 'grep -vq "^//" {} || echo {}' \;
Note that this will report empty files.
The argument to grep can easily be expanded to account for whitespace, or generalized to match an arbitrary regex.
There is no way to achieve this with a simple search style with the components you've mentioned. Doing this would require a bit of interpretation on the file but could be done with a fairly simple script.
It sounds like you're looking for files without code though vs. files with all comments. For example if there are 1000 lines where 900 are commented and 100 are blank, it seems to meet your criteria.
The script should be fairly straight forward to write but you would need to look out for the following weird cases
Block comments
if blocks which are always false. For example #if 0
Empty lines
Well, you could write a program (probably a console app) to recursively walk the directory and file tree. Read in all .cs files and check each line to see if its first non-space and non-tab characters are "//". If you wanted to get really fancy, you could count the total lines and the lines with "//" and display the percentages so you could catch files that didn't have absolutely every line commented out. You'll just need to understand a little bit about System.IO to get the files and string functions to look for the characters you are looking for. That should cover it.
This should be close to what you're looking for: http://www.codeproject.com/KB/cs/csharplinecounter.aspx
Look for the method in the project that determines if a line is commented or not, and you can use that to build a count, etc.

Resources