I have shell scripts that could or could not contain Windows line breaks. I want to convert all existing Windows line breaks to Unix-style, and not destroy the file in the process. I used dos2unix
on my development server, but I found out that it’s not installed on the production server, and I cannot install it there. I have to find an alternative that does the exact same thing as dos2unix
. In particular, I need the result to have the same attributes as the original file: if the file was executable before conversion, it must be executable afterwards.
Asked
Active
Viewed 56 times
0

Stephen Kitt
- 434,908

Jules
- 1
col
command, with those specific redirections, to erase most of the data in the file pointed to by$path
. Additionally, if the current shell iszsh
, thepath
variable is special (an array containing the paths listed in$PATH
), so if you changed its value,col
may not be found at all (that goes for thedos2unix
command as well, obviously) – Kusalananda Feb 10 '23 at 12:04col
is not the tool. – Marcus Müller Feb 10 '23 at 12:08busybox dos2unix
if your system hasbusybox
. – Kusalananda Feb 10 '23 at 12:10dos2unix
or any other conversion solution on your production system because it's already fixed before it gets to production. – Chris Davies Feb 10 '23 at 12:16dos2unix
on the production system before running them, which would introduce unnecessary complexity. – Kusalananda Feb 10 '23 at 12:20tr
. – Chris Davies Feb 10 '23 at 12:21Thanks to the people who tried to help without being condescending.
– Jules Feb 10 '23 at 15:25filename=$(basename -- "$f") extension="${filename##*.}"
newPath=$(echo "$f" | sed "s#/home/jwe/#/var/#g") echo "Copy $f to $newPath" cp "$f" "$newPath"
if [ "$extension" = "sh" ] then echo "Convert shell script to Unix $newPath" dos2unix $newPath fi fi done }`
– Jules Feb 10 '23 at 15:55sed
command given here will preserve the executable bit. – Stephen Kitt Feb 10 '23 at 15:58