Skip to content

Instantly share code, notes, and snippets.

@adrienjoly
Last active January 25, 2023 17:57
Show Gist options
  • Save adrienjoly/747aba1ccc4b5626254359b19d14bb5c to your computer and use it in GitHub Desktop.
Save adrienjoly/747aba1ccc4b5626254359b19d14bb5c to your computer and use it in GitHub Desktop.
This script extracts the first line from stdin, then escapes single quotes, so it can be safely passed as an argument.
# This script extracts the first line from stdin,
# then escapes single quotes, so it can be safely passed as an argument.
# get first line from stdin
FIRST_LINE=$(cat - | head -1)
# escape single quotes
echo "${FIRST_LINE}" | sed -e "s/'/'\\\\''/g"
./escape_single_quotes_from_first_line.sh << EOF
'first' "line"
second line
third line
EOF
# => should return: '\''first'\'' "line"
jobs:
dummy:
steps:
- name: Get Commit Message
run: |
FIRST_LINE=$(git log --format=%B -n 1 ${{ github.event.after }} | ./escape_single_quotes_from_first_line.sh)
echo "message=${FIRST_LINE}" >> $GITHUB_OUTPUT
id: extract_message
- name: Pass To Mycommand
run: ./mycommand --message '${{ steps.extract_message.outputs.message }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment