{"thread":{"id":"32501","subject":"[PATCH 2/4] t9810: Do not use sed -i","startedAt":"2013-01-01T21:40:37Z","lastAt":"2013-01-01T22:12:40Z","messageCount":2,"participants":["Torsten Bögershausen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"205789","messageId":"201301012240.37769.tboegi@web.de","threadId":"32501","inReplyTo":null,"subject":"[PATCH 2/4] t9810: Do not use sed -i","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2013-01-01T21:40:37Z","receivedAt":"2013-01-01T21:40:37Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"sed -i is not portable on all systems.\nUse sed with different input and output files.\nUtilize a tmp file whenever needed\n\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n---\n t/t9810-git-p4-rcs.sh | 24 ++++++++++++++----------\n 1 file changed, 14 insertions(+), 10 deletions(-)\n\ndiff --git a/t/t9810-git-p4-rcs.sh b/t/t9810-git-p4-rcs.sh\nindex 0c2fc3e..5bf9291 100755\n--- a/t/t9810-git-p4-rcs.sh\n+++ b/t/t9810-git-p4-rcs.sh\n@@ -26,10 +26,8 @@ test_expect_success 'init depot' '\n \t\tline7\n \t\tline8\n \t\tEOF\n-\t\tcp filek fileko &&\n-\t\tsed -i \"s/Revision/Revision: do not scrub me/\" fileko\n-\t\tcp fileko file_text &&\n-\t\tsed -i \"s/Id/Id: do not scrub me/\" file_text\n+\t\tsed <filek \"s/Revision/Revision: do not scrub me/\" >fileko\n+\t\tsed <fileko \"s/Id/Id: do not scrub me/\" >file_text\n \t\tp4 add -t text+k filek &&\n \t\tp4 submit -d \"filek\" &&\n \t\tp4 add -t text+ko fileko &&\n@@ -88,7 +86,8 @@ test_expect_success 'edit far away from RCS lines' '\n \t(\n \t\tcd \"$git\" &&\n \t\tgit config git-p4.skipSubmitEdit true &&\n-\t\tsed -i \"s/^line7/line7 edit/\" filek &&\n+\t\tsed <filek \"s/^line7/line7 edit/\" >filek.tmp &&\n+\t\tmv -f filek.tmp filek &&\n \t\tgit commit -m \"filek line7 edit\" filek &&\n \t\tgit p4 submit &&\n \t\tscrub_k_check filek\n@@ -105,7 +104,8 @@ test_expect_success 'edit near RCS lines' '\n \t\tcd \"$git\" &&\n \t\tgit config git-p4.skipSubmitEdit true &&\n \t\tgit config git-p4.attemptRCSCleanup true &&\n-\t\tsed -i \"s/^line4/line4 edit/\" filek &&\n+\t\tsed <filek \"s/^line4/line4 edit/\" >filek.tmp &&\n+\t\tmv -f filek.tmp filek &&\n \t\tgit commit -m \"filek line4 edit\" filek &&\n \t\tgit p4 submit &&\n \t\tscrub_k_check filek\n@@ -122,7 +122,8 @@ test_expect_success 'edit keyword lines' '\n \t\tcd \"$git\" &&\n \t\tgit config git-p4.skipSubmitEdit true &&\n \t\tgit config git-p4.attemptRCSCleanup true &&\n-\t\tsed -i \"/Revision/d\" filek &&\n+\t\tsed <filek \"/Revision/d\" >filek.tmp &&\n+\t\tmv -f filek.tmp filek &&\n \t\tgit commit -m \"filek remove Revision line\" filek &&\n \t\tgit p4 submit &&\n \t\tscrub_k_check filek\n@@ -139,7 +140,8 @@ test_expect_success 'scrub ko files differently' '\n \t\tcd \"$git\" &&\n \t\tgit config git-p4.skipSubmitEdit true &&\n \t\tgit config git-p4.attemptRCSCleanup true &&\n-\t\tsed -i \"s/^line4/line4 edit/\" fileko &&\n+\t\tsed <fileko \"s/^line4/line4 edit/\" >fileko.tmp &&\n+\t\tmv -f fileko.tmp fileko &&\n \t\tgit commit -m \"fileko line4 edit\" fileko &&\n \t\tgit p4 submit &&\n \t\tscrub_ko_check fileko &&\n@@ -189,12 +191,14 @@ test_expect_success 'do not scrub plain text' '\n \t\tcd \"$git\" &&\n \t\tgit config git-p4.skipSubmitEdit true &&\n \t\tgit config git-p4.attemptRCSCleanup true &&\n-\t\tsed -i \"s/^line4/line4 edit/\" file_text &&\n+\t\tsed <file_text \"s/^line4/line4 edit/\" >file_text.tmp &&\n+\t\tmv -f file_text.tmp file_text &&\n \t\tgit commit -m \"file_text line4 edit\" file_text &&\n \t\t(\n \t\t\tcd \"$cli\" &&\n \t\t\tp4 open file_text &&\n-\t\t\tsed -i \"s/^line5/line5 p4 edit/\" file_text &&\n+\t\t\tsed <file_text \"s/^line5/line5 p4 edit/\" >file_text.tmp &&\n+\t\t\tmv -f file_text.tmp file_text &&\n \t\t\tp4 submit -d \"file5 p4 edit\"\n \t\t) &&\n \t\techo s | test_expect_code 1 git p4 submit &&\n-- \n1.8.0.197.g5a90748\n"},{"id":"205800","messageId":"7v38yk8sdj.fsf@alter.siamese.dyndns.org","threadId":"32501","inReplyTo":"201301012240.37769.tboegi@web.de","subject":"Re: [PATCH 2/4] t9810: Do not use sed -i","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-01-01T22:12:40Z","receivedAt":"2013-01-01T22:12:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Torsten Bögershausen <tboegi@web.de> writes:\n\n> sed -i is not portable on all systems.\n> Use sed with different input and output files.\n> Utilize a tmp file whenever needed\n>\n> Signed-off-by: Torsten Bögershausen <tboegi@web.de>\n> ---\n>  t/t9810-git-p4-rcs.sh | 24 ++++++++++++++----------\n>  1 file changed, 14 insertions(+), 10 deletions(-)\n>\n> diff --git a/t/t9810-git-p4-rcs.sh b/t/t9810-git-p4-rcs.sh\n> index 0c2fc3e..5bf9291 100755\n> --- a/t/t9810-git-p4-rcs.sh\n> +++ b/t/t9810-git-p4-rcs.sh\n> @@ -26,10 +26,8 @@ test_expect_success 'init depot' '\n>  \t\tline7\n>  \t\tline8\n>  \t\tEOF\n> -\t\tcp filek fileko &&\n> -\t\tsed -i \"s/Revision/Revision: do not scrub me/\" fileko\n> -\t\tcp fileko file_text &&\n> -\t\tsed -i \"s/Id/Id: do not scrub me/\" file_text\n> +\t\tsed <filek \"s/Revision/Revision: do not scrub me/\" >fileko\n> +\t\tsed <fileko \"s/Id/Id: do not scrub me/\" >file_text\n\nMaking it shorter and more correct ;-), which is good, but you are\nlosing the && chaining.  Also it is more customary to have\nredirection at the end, unless it is to redirect a numbered file\ndescriptor (e.g. \"echo >&2 error message\").  I.e.\n\n\tsed \"s/Revision/Revision: do not scrub me/\" <filek >fileko &&\n\tsed \"s/Id/Id: do not scrub me/\" <fileko >file_text\n"}]}