This question already has an answer here:
I have a file
/tmp/pathnames where each line is a pathname to a dir.
/tmp/my dir1 /tmp/dir2 /tmp/dir3
I want to apply the command
pushd to each line in the file, so that I can have those pathnames in the dir stack of the current shell.
Here is a bash script for that purpose:
#! /bin/bash cat /tmp/pathnames | while read pathname; do pushd "$pathname" done
But it doesn't work as I expected, i.e. no stack of dirs is created for my current shell.
Even if I run the commands in the script in the shell directly with
source, it still does not work.
I wonder why and how to solve the problem?