# Generate url with variable [duplicate]

Im trying to use the hyperref package for creating a link to a website with a dynamic url. I have a script that outputs an id that should be used in the url.

I have been trying to wrap my head around this for hours trying to figure how to achieve this but as a fairly new user of TeX I must admit defeat now.

Here is an example of what I want to do:

\newcommand{\getid}[0]
{
\input{|"get-id.sh"}
}

{
\getid \\ % Just for debugging
}


This produces the id correctly but on the next line there is nothing remotely what I want, more exactly just "\let\reserved@d=\bgroup\def{\@@par}".

I have also tried \edef\getid{\input{|"get-id.sh"}} with the same result even though I feel like that should evaluate the input before I try to use the variable.

Using \def\getid{MyStaticID} works just fine so the problem only appears when using \input.

Possible workarounds could be to write the value with TeX code to a file and then import it, alternatively pass it to the code using pdftex. I would however prefer to do it in the TeX file as I am trying to do but is it even possible or a limitation somewhere I will have to live with?

• Looked at this again. The solution is to use \begingroup\makeatletter\endlinechar=\m@ne\everyeof{\noexpand} \edef\x{\endgroup\def\noexpand\gitid{\@@input|"./get-id.sh" }}\x . This comes from tex.stackexchange.com/questions/16790/…, which also has an explanation. There are also other solutions using various packages given on this page. – Andrew Feb 14 '18 at 10:28