In the original [comand] all the new lines \ carriage returns, tab exist.
If we change this line in step 3 of the script to replace it with \n, \r and \t
+ ', ' + '@command='+ 'N''' + COALESCE(command,'') + ''''
+ ', ' + '@command='+ 'N''' + COALESCE(replace(replace(replace(command,char(10),'\n'),char(13),'\r'),char(9),'\t'),'') + ''''
We would get a job step in one line as well, but then we could try something like that after the job is restored, but this is directly updating the system table which I do not really like. ]
DECLARE @JobName NVARCHAR(MAX) = N'JobName_RESTORED';
SET sjs.command = replace(replace(replace(command,'\n',char(10)),'\r',char(13)),'\t',char(9))
FROM dbo.sysjobs AS sj
JOIN dbo.sysjobsteps AS sjs ON sj.job_id = sjs.job_id
WHERE sj.name = @JobName;
I would prefer to "patch" the restored job afterwards with msdb.dbo.sp_update_jobstep. My initial test shows it works if we do not print out the step command into the grid.
It is a good exercise.