Home > Enterprise >  Unexpected question mark in Windows/bash
Unexpected question mark in Windows/bash

Time:04-15

I'm trying to automatically "archive" some local branches on Windows using the MinGW Bash on Windows.

I copy and pasted the content of git branch on a txt file (branches_to_be_archived.txt) and then I wrote:

A script to archive a single branch

#!/bin/bash
BRANCH_NAME=$1
echo "Branch name is $BRANCH_NAME"
git tag archive/$BRANCH_NAME $BRANCH_NAME
git branch -D $BRANCH_NAME

A script to archive every branch from a file

#!/bin/bash
FILE=./branches_to_be_archived.txt
LINES=$(cat $FILE)
for LINE in $LINES
do
    ./archive_branch.sh.txt $LINE
done

I inserted some echo prints and they are ok but executing git commands will raise an error like this:

fatal: Failed to resolve '[actual name of the branch]?' as a valid ref.

With a trailing ? that is not shown anywhere.

Any way to avoid having this question mark at the end?

CodePudding user response:

Indeed, it was a endline characters issue (Win CRLF and Linux LF).

I solved by using Notepad and setting EOL -> Linux (LF) but I think that dos2unix for branches list file works just fine

  • Related