I am using Notepad++ for creating scripts and opening my active files from menu "Run" -> "Open current dir cmd". This works fine and the result is:
c:\scripts>
What I would like to have is the filename that I am working on currently so that I could try testing it right away. In my scripts I use parameters to define input and output files. Therefore the script shouldn't be run while opening, rather to have the script typed into console:
c:\scripts>edit_text.pl
I would then add manually the needed input and output files
c:\scripts>edit_text.pl input.txt output.txt
How do I make this possible in Notepad++ "Run" -feature?
Currently it is defined in shortcuts.xml as
cmd /K cd $(CURRENT_DIRECTORY)
I suspect that it would be something like this:
cmd /K cd $(CURRENT_DIRECTORY) $(FILE_NAME)
The problem is that this will "execute" the filename as well. I would like to have it waiting on the console for my actions.
Thanks in advance!
The final code line would mean the CD and the script invocation being treated as one command. Separating then with && should help.
cmd /K cd $(CURRENT_DIRECTORY) && $(FILE_NAME)
However, that would do the CD then execute the command. I do not know of any way to enter a command but not execute it.
A poor solution would use the command below. You could copy and paste the echoed command then add in any parameters needed. Setting "Quick edit" mode on the window would make the copy and paste quicker.
cmd /K cd $(CURRENT_DIRECTORY) && ECHO $(FILE_NAME)
I have adopted a different approach for my own scripts although they do not have parameters that I need to enter. Edit the file (but not with Notepad++ as it overwrites the file just before it exits):
C:\Users\AdrianHHH\AppData\Roaming\Notepad++\shortcuts.xml
I have added some lines to the <UserDefinedCommands> section:
<NotepadPlus>
... unchanged
<UserDefinedCommands>
... unchanged
<Command name="Open containing folder" Ctrl="no" Alt="no" Shift="no" Key="0">explorer $(CURRENT_DIRECTORY)</Command>
<Command name="Open current dir cmd" Ctrl="no" Alt="no" Shift="no" Key="0">cmd /K cd /d $(CURRENT_DIRECTORY)</Command>
<Command name="Run as command" Ctrl="no" Alt="no" Shift="no" Key="0">cmd /C "cd /d $(CURRENT_DIRECTORY) && $(FULL_CURRENT_PATH)"</Command>
<Command name="Explorer with selection" Ctrl="no" Alt="no" Shift="no" Key="0">explorer $(CURRENT_WORD)</Command>
</UserDefinedCommands>
... unchanged
</NotepadPlus>
Related
I would like to invoke R script by using a .bat file.
For testing, I saved an R file on the desktop in the name print_test.R
The code in this file is:
p<-500
write.csv(p,"print.csv")
I wrote the .bat file :
#echo off
R CMD BATCH C:\Users\User\Desktop\print_test.R
UPDATE:
After adding pause to the .bat file I got the following text:
"'R' is not recognized as an internal or external command,
operable program or batch file.
Press any key to continue . . ."
When I click on the bat file (also saved on the desktop) there is a blink of the CMD window but the print.csv file is not created.What is wrong?
Consider using the automated utility, Rscript.exe, as the R CMD BATCH might be considered a legacy command. See post: R.exe, Rcmd.exe, Rscript.exe and Rterm.exe: what's the difference?
Rscript as an environment PATH variable:
#echo off
Rscript "C:\Users\User\Desktop\print_test.R"
Rscript not as a environment PATH variable (where you specify full path of the executable -usually in bin folder of installation):
#echo off
"C:\Path\To\Rscript" "C:\Users\User\Desktop\print_test.R"
OR if paths do not have spaces:
#echo off
C:\Path\To\Rscript C:\Users\User\Desktop\print_test.R
I followed Sumedh's tip :
here is the new code:
#echo off
"C:\Program Files\R\R-3.2.4\bin\x64\r.exe" CMD BATCH "C:\Users\User\Desktop\print_test.R"
For building my target I have a list of prerequisites contained in a file list.txt and a script for generating this file generate-list.sh.
I need the script to be executed as first thing every time I invoke the make in order to have the list.txt updated and to give ti make the right list of prerequisites.
prebuild:
touch list.txt
.SECONDEXPANSION:
exe: prebuild $$(shell cat list.txt)
touch exe
<files in list.txt>:
<rules for generating these files>
In this way when I run make I first get an error from cat saying that list.txt does not exist, then list.txt is generated but since the cat failed the prerequisites contained in list.txt are not generated.
One method you could use, given that generate_list.sh must be executed at the very start every time, would be to explicitly execute it using the shell function. This would mean altering your makefile to something like
$(shell ./generate_list.sh > /dev/null)
.SECONDEXPANSION:
exe: $(shell cat list.txt)
touch exe
#echo $?
<files in list.txt>:
<rules for generating these files>
Executing this makefile produces
$ make
touch exe
deps.c test.c
where my generate_list.sh file contains
#!/bin/bash
touch test.c deps.c
echo deps.c test.c > list.txt
echo 'Created prerequisites list.'
Notes
/dev/null is included in $(shell ./generate_list.sh > /dev/null) incase your generate_list.sh produces an output as this would cause an error in make of
$ make
GNUmakefile:1: *** missing separator. Stop.
otherwise.
#echo $? shows that all of the prerequisites in list.txt are now included as prerequisites of exe.
Alternate Method Based on Auto Dependency Generation
What you are attempting to do is very similar to automatic dependency generation which can be accomplished using the -include directive in make. For future usage you may want to consider going down this route and altering your generate_list.sh script to create a makefile that can be included in your main makefile.
I need to execute a short script that just renames a few files (mv).
The script is in about 50 folders, each folder is named and currently I'm executing them from the shell and moving to the next folder using:
bash rename && cd ../folder01
Then pressing up and changing the last digit(s).
Is there a way to execute the script in all folders in one line?
Sure, use a for loop:
for f in folder*; do (cd "$f" && bash rename) ; done
Suppose the structure:
/foo/bar/
--file1
--file2
--file3
--folder1
--file4
--folder2
--file5
I want to run the unix zip utility, compressing the bar folder and all of it's files and subfolders, from foo folder, but not have the bar folder inside the zip, using only command line.
If I try to use the -j argument, it doesn't create the bar folder inside the zip as I want, but doesn't create folder1 and folder2. Doing -rj doesn't work.
(I know I can enter inside bar and do zip -r bar.zip . I want to know if it's possible to accomplish what $/foo/bar/ zip -r bar.zip . but doing it from $/foo).
You have to do cd /foo/bar then zip -r bar.zip ., however, you can group them with parentheses to run in a subshell:
# instead of: cd /foo/bar; zip -r bar.zip; cd -
( cd /foo/bar; zip -r bar.zip . )
The enclosed (paren-grouped) commands are run in a subshell and cd within it won't affect the outer shell session.
See sh manual.
Compound Commands
A compound command is one of the following:
(list) list is executed in a subshell environment (see COMMAND EXECUTION ENVIRONMENT below).
Variable assignments and builtin commands that affect the shell's environment do not remain in effect after the command completes.
The return status is the exit status of list.
zip doesn't have a -C (change directory) command like tar does
you can do:
cd folder1 && zip -r ../bar.zip *
from within a command line shell
or you can use bsdtar which is a version of tar from libarchive that can create zips
bsdtar cf bar.zip --format zip -C folder1 .
(this creates a folder called ./ -- not sure a way around that)
I can't speak for the OP's reasoning. I was looking for this solution as well.
I am in the middle of coding a program that creates an .ods by building the internal xml files and zipping them together. They must be in the root dir of the archive, or you get an error when you try and run OOo.
I'm sure there is a dozen other ways to do this:
create a blank .ods file in OOo named blank.ods, extract to dir named blank, then try running:
cd blank && zip -r ../blank.ods *
The way I wrote mine, the shell closes after one command, so I don't need to navigate back to the original directory, if you do simply add && cd .. to the command line:
cd blank && zip -r ../blank.ods * && cd ..
I have the following script
#!/usr/bin/Rscript
print ("shebang works")
in a file called shebang.r. When I run it from command line using Rscript it works
$ Rscript shebang.r
but when I run it from the command line alone
$ shebang.r
It doesn't work. shebang.r command not found.
If I type (based on other examples I've seen)
$ ./shebang.r
I get permission denied.
Yes, Rscript is located in /usr/bin directory
Make the file executable.
chmod 755 shebang.r
In addition to Sjoerd's answer... Only the directories listed in the environment variable PATH are inspected for commands to run. You need to type ./shebang.r (as opposed to just shebang.r) if the current directory, known as ., is not in your PATH.
To inspect PATH, type
echo $PATH
To add . to PATH, type
export PATH="$PATH:."
You can add this line to your ~/.bashrc to make it happen automatically if you open a new shell.