Hi,
I was stuck on the shell challange at the history file from env variable. Something wierd happens and the first item of readline_list_history() is an emptry string.
To work around it, I wrote this (admittedly ugly) piece of code, but I’m still not sure why the empty string shows up in the first place.
All code is here.
Any insights would be greatly appreciated!
Thanks,
Razvan
global $history;
$localHistory = readline_list_history();
if (isset($localHistory[0]) && isset($history[0])) {
$localHistory[0] = $history[0];
}
$offset = (int) ($this->args[0] ?? 0);
$prevCommands = array_slice($localHistory, -$offset, null, true);
foreach ($prevCommands as $index => $prevCommand) {
$line = sprintf('%5d %s', $index + 1, trim($prevCommand));
fwrite($this->out, $line . PHP_EOL);
}