I created a bash script :
#!/bin/bash
su root -c vim $1 -c ':%s/^M//g' -c 'wq'
My script has to remove all the ^M (carriage return on Windows) on my file, then save it.
When I execute my script it returns :
/sequenceFiles/Sequence1.seq: wq: command not found
Does someone know why ? Thanks for your help.
The -c
is seen by su
, not vim
, and the shell complains about the unknown command.
You need to pass the command as one argument to su
:
su root -c "vim $1 -c ':%s/^M//g' -c 'wq'"
man su
says:
`-c COMMAND'
`--command=COMMAND'
Pass COMMAND, a single command line to run, to the shell with a
`-c' option instead of starting an interactive shell.
Try
su root -c "vim $1 -c ':%s/^M//g' -c 'wq'"
虽然你可以用vim做,但考虑更简单:
perl -pi -e 's/\r\n/\n/' file
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.