[PR]: sed -i is not posix. #1

Open
opened 2026-05-26 22:14:32 +02:00 by euro · 1 comment

Instead read the file before hand and modify as needed.

This keeps the original behavior where it doesn't overwrite the file entirely (though i'm not sure why this is done)

diff --git a/source_code/shmake_link_library.sh b/source_code/shmake_link_library.sh
index e763592..9b8072e 100644
--- a/source_code/shmake_link_library.sh
+++ b/source_code/shmake_link_library.sh
@@ -31,23 +31,21 @@ add_linked_library()
         if [ -f "shmake_config/linked.conf" ]; then
                 printf "Note: 'linked.conf' already exists.\n"
                 printf "Current linked libraries:\n"
-                cat "shmake_config/linked.conf"
+                old_file=$(cat "shmake_config/linked.conf")
+                printf "%s" "$old_file"
                 printf "\nAppend? [y/N]: "
+
                 read -r append_choice
-                       case "$append_choice" in
+                        case "$append_choice" in
                                 y|Y)
-                                        old_libs=$(grep '^LINKED_LIBS' "shmake_config/linked.conf" | sed 's/^LINKED_LIBS = //')
                                         new_libs="$old_libs $LIB_FLAGS"
-                                        sed -i '/^LINKED_LIBS/d' "shmake_config/linked.conf"
-                                        printf "LINKED_LIBS = %s\n" "$new_libs" >> "shmake_config/linked.conf"
-                                        printf "Linked libraries appended successfully!\n"
                                         ;;
                                 *)
-                                        sed -i '/^LINKED_LIBS/d' "shmake_config/linked.conf"
-                                        printf "LINKED_LIBS = %s\n" "$LIB_FLAGS" >> "shmake_config/linked.conf"
-                                        printf "Linked libraries overwritten successfully!\n"
+                                        new_libs="$LIB_FLAGFS"
                                         ;;
                         esac
+                printf "%s\nLINKED_LIBS = %s" "$(printf "%s" "$old_file" | sed '/^LINKED_LIBS/d')" "$new_libs" > "shmake_config/linked.conf"
+                printf "Linked libraries appended successfully!\n"
         else
                 cat > "shmake_config/linked.conf" << EOF
 # --- shmake Linked Libraries Configuration ---
Instead read the file before hand and modify as needed. This keeps the original behavior where it doesn't overwrite the file entirely (though i'm not sure why this is done) ```patch diff --git a/source_code/shmake_link_library.sh b/source_code/shmake_link_library.sh index e763592..9b8072e 100644 --- a/source_code/shmake_link_library.sh +++ b/source_code/shmake_link_library.sh @@ -31,23 +31,21 @@ add_linked_library() if [ -f "shmake_config/linked.conf" ]; then printf "Note: 'linked.conf' already exists.\n" printf "Current linked libraries:\n" - cat "shmake_config/linked.conf" + old_file=$(cat "shmake_config/linked.conf") + printf "%s" "$old_file" printf "\nAppend? [y/N]: " + read -r append_choice - case "$append_choice" in + case "$append_choice" in y|Y) - old_libs=$(grep '^LINKED_LIBS' "shmake_config/linked.conf" | sed 's/^LINKED_LIBS = //') new_libs="$old_libs $LIB_FLAGS" - sed -i '/^LINKED_LIBS/d' "shmake_config/linked.conf" - printf "LINKED_LIBS = %s\n" "$new_libs" >> "shmake_config/linked.conf" - printf "Linked libraries appended successfully!\n" ;; *) - sed -i '/^LINKED_LIBS/d' "shmake_config/linked.conf" - printf "LINKED_LIBS = %s\n" "$LIB_FLAGS" >> "shmake_config/linked.conf" - printf "Linked libraries overwritten successfully!\n" + new_libs="$LIB_FLAGFS" ;; esac + printf "%s\nLINKED_LIBS = %s" "$(printf "%s" "$old_file" | sed '/^LINKED_LIBS/d')" "$new_libs" > "shmake_config/linked.conf" + printf "Linked libraries appended successfully!\n" else cat > "shmake_config/linked.conf" << EOF # --- shmake Linked Libraries Configuration --- ```
Owner

holymoly bruh I thought I got rid of all the sed -i's

this project didn't start as fully posix, but I have been trying to update it to be so for the last few weeks of working on it

I'll update that in a bit

holymoly bruh I thought I got rid of all the sed -i's this project didn't start as fully posix, but I have been trying to update it to be so for the last few weeks of working on it I'll update that in a bit
Sign in to join this conversation.
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: epochryphon/shmake#1