Unwanted Line Breaks in Shell Command (from VIM) [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I am trying to run a shell command in VIM using "exe." I have a variable that contains the result of a system call (a pathname)
tempName=system('run.sh') "tempname is actually equal to "/path/to/file/tempfile.do"
I want to use the variable tempName in another shell command:
exe '! cat '.tempName.' >> anotherFile'
So what should run is:
cat /path/to/file/tempFile.do >> anotherFile
but for some reason the " >> anotherFile" part is cut off and only
cat /path/to/file/tempFile.do
is running. I tried escaping the ">>" characters and the "." which did not work. Any ideas?

Does it work when you type it literally?
:execute '!cat /path/to/file/tempFile.do >> anotherFile'
If so, then the problem is that system() captures the output including the newlines.
One solution is to strip the final newline using substitute():
:execute '!cat '.substitute(tempName, '\n$', '', '').' >> anotherFile'

This works for me. Note the space after cat
:exe '! cat '.tempName.' >> anotherFile'

Related

Fill in command input [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I'm trying to enter input without typing anything I'm trying to put the input in the command.
I've seen people try this:
printf 'argument\n' | command
Or
command <<< "argument\n"
I don't know if what I'm doing is command specific but neither of these work for what I'm trying to do.
I'm trying to zip a file with a password:
zip -r -e test.zip test_zip/
-e is for password input (this isn't the part I was talking). I set the password to test1234.
When I unzip the file I try things like this:
printf 'test1234\n' | unzip test.zip
But it still asks for password input.
Any suggestions?
If you are using the Linux command line, try using echo.
echo 'test1234' | unzip test.zip
Use the -P argument
unzip -P <password> <zipfile>

How to display all commands of the bash shell in a file? Linux [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
So I have an assignment in linux terminal asking me to create a file in the home directory and to make the file display all the commands of the bash shell which is found in the /bin directory.
I already tried to use the echo command to display the commands to the file but it is not working:
echo $ls /bin > File1
I expect that the file contains all the commands of the bash shell, but when I type the line above in the linux terminal, the content of the file is just the word "/bin".
Is there any other way to use to meet the expected result?
Here you don't need the echo command, as ls already prints to standard output, which can then be piped to the file. The command you want is:
ls /bin > File1
A good way to go about this is by checking that "ls /bin" by itself will print to standard output the contents of /bin, and once you see the expected output, run it again with the "> File1" to then output to File1.

Linux commands explanation [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
I can't find this in the linux --help.
may you please tell me what theses commands are dowing
NAME=gs://toto-titi-dfs-dfe-gfd-zed/
then the ambiguous commands are :
NAME="${NAME//\\/\\\\}"
NAME="${NAME//\//\\/}"
then we have these two commands:
sudo sed -i "s/spark\.eventLog\.dir.*/spark\.eventLog\.dir $NAME/g" /usr/lib/spark/conf/spark-defaults.conf
sudo sed -i "s/spark\.history\.fs\.logDirectory.*/spark\.history\.fs\.logDirectory $NAME/g" /usr/lib/spark/conf/spark-defaults.conf
Which I can't understand too
Any help with this please
Thanks a lot
Set the variable NAME to the string gs://toto-titi-dfs-dfe-gfd-zed/
Swap out all instances of \ with \\ in that variable using NAME="${NAME//\\/\\\\}" Read about Shell Parameter Expansion here specifically the section labelled ${parameter/pattern/string}.
Swap out all instaces of / with \/ in the NAME variable using AME="${NAME//\//\\/}". These two steps are being performed to escape out the / and \ in the NAME variable so that sed doesn't choke.
In file /usr/lib/spark/conf/spark-defaults.conf replace out matches of spark.eventLog.dir.* with spark.eventLog.dir $NAME
In file /usr/lib/spark/conf/spark-defaults.conf replace out matches of spark.history.fs.logDirectory.* with spark.history.fs.logDirectory $NAME

rename multiple filename in linux [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I have many files named xxxx.min.js and want to rename the files to xxxx.js so basically want to remove .min only.
Is there a command I can use to do this job?
I thought using rename command would be easy for each single file, but that would take forever since I have many of them.
any idea?
Here's a bash-only command (not requiring Perl)
for i in *.min.js; do a=$(basename $i .min.js); echo mv $i $a.js; done
Explanation
for i in *.min.js; do
loop over all files matching *.min.js
a=$(basename $i .min.js)
extract the base name of the file (i.e. strip off .min.js) and save the result in $a
echo mv $i $a.js
for now, print to the console the command that WOULD be run if you removed the echo
When you are satisfied that it generates the correct commands, remove the echo to actually rename the files.
Ubuntu and Debian linux distribution both have a perl version of mv function called rename or prename, which supports regexp. The manual can be found here.
Go to the folder of the files and run the command as follows:
rename s/\.min\.js$/\.js/ *.min.js

Copy a line from text file to shell [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
Hello dear smart people,
If I'm in a login linux shell and I'm browsing a text file full of lines with vim or cat.
example
mar#001:~$ cat test
sudo kill pluto
sudo echo $Parerino
sudo cut -d -f--d-f a -sdf-s-f 2> myerr
sudo kill pluto
sudo echo $PATH
sudo echo $Parerino
How is possible to do the copy of the "sudo cut -d -f--d-f a -sdf-s-f 2> myerr" command, after I closed the file and paste it in the shell so then I can execute it? or may I do it automatically?
How can I do that copy of that command that I need then open a new shell and paste the long command to modify it before to execute it?
Since you most likely don't have a clipboard you won't be able to copy/paste from Vim to the shell.
But you can yank the current line and execute it with :!:
0y$
:!<C-r>"<CR>
Or you can execute the current line as returned by getline:
:!<C-r>=getline('.')<CR><CR>
Or you can write the line into a file and execute its content:
:.w foo
<C-z>
$ cat foo | sh
Or you can remember the line of your command, quit Vim and do:
sed -e 5p | sh
If no GUI at all, then I can only think of gpm and screen. You may want to take a look at the following thread: https://superuser.com/questions/67644/linux-copy-paste-in-tty

Resources