logo
down
shadow

Store Git ID in variable in batch script


Store Git ID in variable in batch script

By : Gurwinder Singh Ghum
Date : November 19 2020, 03:01 PM
With these it helps Seems like you are mixing bash and batch scrips. If you are on Windows, you can assign the output of a command to a variable using 'temporary' files:
code :
git rev-parse @~ > prev_com.txt
set /p prev_com=<prev_com.txt
git rev-parse HEAD > curr_com.txt
set /p curr_com=<curr_com.txt
for /f %%i in ('git rev-parse @~')   do set prev_com=%%i
for /f %%i in ('git rev-parse HEAD') do set curr_com=%%i
prev_com=$(git rev-parse @~)
git show HEAD
git show --pretty= HEAD


Share : facebook icon twitter icon
How to count no of lines in text file and store the value into a variable using batch script?

How to count no of lines in text file and store the value into a variable using batch script?


By : user2957209
Date : March 29 2020, 07:55 AM
With these it helps You could use the FOR /F loop, to assign the output to a variable.
I use the cmd-variable, so it's not neccessary to escape the pipe or other characters in the cmd-string, as the delayed expansion passes the string "unchanged" to the FOR-Loop.
code :
@echo off
cls
setlocal EnableDelayedExpansion
set "cmd=findstr /R /N "^^" file.txt | find /C ":""

for /f %%a in ('!cmd!') do set number=%%a
echo %number%
how to store output of sql query in variable in batch script?

how to store output of sql query in variable in batch script?


By : Olori Temi Adebayo
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , i am working on a batch script. , I can see at least two issues in your script:
code :
SETLOCAL EnableDelayedExpansion

FOR /F "usebackq" IN ("F:\count.txt") DO (
SET output=%%a
ECHO !output!
)
Batch script: Search two strings in log file and store values in variable

Batch script: Search two strings in log file and store values in variable


By : user3536044
Date : March 29 2020, 07:55 AM
This might help you I don't like the idea of creating a variable with a comma delimited list of keys, but here you go.
Pure batch
code :
@echo off
setlocal enableDelayedExpansion
set "noConnection="
set "keys="
for /f "tokens=1,4" %%A in (
  'findstr /r /c:"The connection to the remote server can not be established\." /c:"^Outgoing Message Key: " input.log'
) do (
  if %%A equ Outgoing (
    if defined noConnection set "keys=!keys!,%%B"
    set "noConnection="
  ) else set noConnection=1
)
set "keys=!keys:~1!"
echo !keys!
@echo off
setlocal enableDelayedExpansion
set "keys="
for /f %%A in (
  'jrepl "The connection to the remote server can not be established\.[\s\S]*?^Outgoing Message Key: (\d+)" "$1" /m /jmatch /f input.log'
) do set "keys=!keys!,%%A"
set "keys=!keys:~1!"
echo !keys!
@echo off
setlocal
for /f %%A in (
  'jrepl "The connection to the remote server can not be established\.[\s\S]*?^Outgoing Message Key: (\d+)"^
         "keys+=','+$1;false" /m /jmatch /jbeg "var keys=''" /jend "output.WriteLine(keys.slice(1))" /f input.log'
) do set "keys=%%A"
echo %keys%
How to get values from text file and store it as a variable in batch script?

How to get values from text file and store it as a variable in batch script?


By : user6999035
Date : March 29 2020, 07:55 AM
around this issue How can I get the specific value from text file and store it at a variable by using batch scripting? , In command line
code :
for /f "tokens=1-26" %a in ('findstr 0000: input.txt') do @echo %r & set var=%r
for /f "tokens=1-26" %%a in ('findstr 0000: input.txt') do @echo %%r & set var=%%r
How to store the result of the expression into a variable in Windows batch script?

How to store the result of the expression into a variable in Windows batch script?


By : Vinod Garia
Date : March 29 2020, 07:55 AM
should help you out Set the variable at each iteration with the delayed expansion activated!!
code :
@echo off
setlocal enabledelayedexpansion

Set "Pattern=\"
Set "Replace=_"

FOR /F "tokens=*" %%x in (server.txt) DO (
  Set "servername=%%x"
  Set "$output=!servername:%Pattern%=%Replace%!"
  echo !$output!
)
Related Posts Related Posts :
  • Pruning branches in Visual Studio 17 git?
  • Fixing Git folder case problems in macOS
  • Could i checkout another branch while current branch pushing processed?
  • How can I make a change to changes in a git branch?
  • Create a pull request in BitBucket, based on a commit hash
  • Jenkins Pipeline Git commit message before scm checkout
  • Jenkins could not locate pom.xml of the project
  • What happens when using an SSH key for git authentication then HTTP for clone?
  • Git- Deleted files getting in the way of merge?
  • Disable/Change Visual Studio Team Services automatic interpretation of hash-number commit messages
  • Git file name changes case on push
  • git clone fail from config script
  • Is there any alternative to the atom package line-diff-details?
  • Git branches results comparison
  • Prevent TeamCity building on fast-forward merge to master if build exists for that SHA1
  • Error launching git when using git command prompt
  • How to reset Git repository to old sate without moving the HEAD
  • YOCTO: "error: cannot run ssh: No such file or directory"
  • How to make a commit to the new master in git
  • gitk not showing diff colors on macOS
  • Need to delete particular commit from bit bucket
  • Don't close issues mentioned in Pull Request commit messages
  • IntelliJ GitLab. Push failed. Failed with error: Authentication failed
  • Github project find all files in .gitingore file | Forcefully added files
  • Git Smart HTTP protocol fails to execute server side hooks on push
  • Is "git rev-parse --short" aware of the current directory?
  • How do I add files to a git project without them being tracked?
  • Git submodule track branch effectivly
  • If I edit local repo directly, what is the point of commits? Where are repo's stored? How does GitHub know who I am?
  • how to create update fucntion for bash script
  • Zsh in iTerm2 completion causing git push error
  • Correct way to merge branch into local branch
  • How can core.autocrlf be still set if it is not set in local/global/system level?
  • Add rsa-keys to the system
  • Git, when renaming on both branches, not detected as rename
  • Download random GitHub repositories with Powershell
  • How do fetch remote branch after I cloned repo with git clone --depth 1
  • Dreamweaver Git integration not able to fetch
  • How Buildroot makes archive of git repository?
  • Azure DevOps git policy configurations api broken?
  • Deleting files locally but not from online github repo
  • Sublime Merge SSH Failing when Key has password
  • How to fix this in git "This branch is out-of-date with the base branch"?
  • Migration from SVN to GitHub
  • how to pull certain file type from a certain Tag
  • Git: get commit diff without checking out code, is it possible?
  • Pushing to Github on Mac returns error everytime
  • How to force my main repo to update when a submodules is updated?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org