Skip to main content
The 2024 Developer Survey results are live! See the results
Post Undeleted by Kusalananda
deleted 46 characters in body
Source Link
Kusalananda
  • 339.1k
  • 37
  • 684
  • 992

DELETED: I don't understand this question.

Since it appears you want to change the working directory every once in a while, a suggestion would be to replace the alias with a shell function, which could take the directory pathname as a command line argument:

do_it () {
    local wd="${1:-my_working_dir}"
    cd "$wd" || return
    do_stuff
 }

This function takes an optional single argument, a directory pathname. If given, the function's local wd variable is set to this value. If not given, the local wd variable is set to the static string my_working_dir.

With a small change, you could disallow the function from leaving the user in an unexpected working directory:

do_it () {
    local wd="${1:-my_working_dir}"
    (
        cd "$wd" || return
        do_stuff
    )
 }

The parenthesised subshell's environment inside the function (which includes the current working directory, possibly modified by cd) would not affect the environment of the calling shell.

You would declare this function wherever you usually declare aliases, and you would use it either as

do_it

or with an argument,

do_it some/directory/path

or, in a loop that runs it over a number of directory pathnames,

for target_dir in some/pattern/dir*/
do
    do_it "$target_dir"
done

DELETED: I don't understand this question.

Since it appears you want to change the working directory every once in a while, a suggestion would be to replace the alias with a shell function, which could take the directory pathname as a command line argument:

do_it () {
    local wd="${1:-my_working_dir}"
    cd "$wd" || return
    do_stuff
 }

This function takes an optional single argument, a directory pathname. If given, the function's local wd variable is set to this value. If not given, the local wd variable is set to the static string my_working_dir.

With a small change, you could disallow the function from leaving the user in an unexpected working directory:

do_it () {
    local wd="${1:-my_working_dir}"
    (
        cd "$wd" || return
        do_stuff
    )
 }

The parenthesised subshell's environment inside the function (which includes the current working directory, possibly modified by cd) would not affect the environment of the calling shell.

You would declare this function wherever you usually declare aliases, and you would use it either as

do_it

or with an argument,

do_it some/directory/path

Since it appears you want to change the working directory every once in a while, a suggestion would be to replace the alias with a shell function, which could take the directory pathname as a command line argument:

do_it () {
    local wd="${1:-my_working_dir}"
    cd "$wd" || return
    do_stuff
 }

This function takes an optional single argument, a directory pathname. If given, the function's local wd variable is set to this value. If not given, the local wd variable is set to the static string my_working_dir.

With a small change, you could disallow the function from leaving the user in an unexpected working directory:

do_it () {
    local wd="${1:-my_working_dir}"
    (
        cd "$wd" || return
        do_stuff
    )
 }

The parenthesised subshell's environment inside the function (which includes the current working directory, possibly modified by cd) would not affect the environment of the calling shell.

You would declare this function wherever you usually declare aliases, and you would use it either as

do_it

or with an argument,

do_it some/directory/path

or, in a loop that runs it over a number of directory pathnames,

for target_dir in some/pattern/dir*/
do
    do_it "$target_dir"
done
added 46 characters in body
Source Link
Kusalananda
  • 339.1k
  • 37
  • 684
  • 992

DELETED: I don't understand this question.

Since it appears you want to change the working directory every once in a while, a suggestion would be to replace the alias with a shell function, which could take the directory pathname as a command line argument:

do_it () {
    local wd="${1:-my_working_dir}"
    cd "$wd" || return
    do_stuff
 }

This function takes an optional single argument, a directory pathname. If given, the function's local wd variable is set to this value. If not given, the local wd variable is set to the static string my_working_dir.

With a small change, you could disallow the function from leaving the user in an unexpected working directory:

do_it () {
    local wd="${1:-my_working_dir}"
    (
        cd "$wd" || return
        do_stuff
    )
 }

The parenthesised subshell's environment inside the function (which includes the current working directory, possibly modified by cd) would not affect the environment of the calling shell.

You would declare this function wherever you usually declare aliases, and you would use it either as

do_it

or with an argument,

do_it some/directory/path

Since it appears you want to change the working directory every once in a while, a suggestion would be to replace the alias with a shell function, which could take the directory pathname as a command line argument:

do_it () {
    local wd="${1:-my_working_dir}"
    cd "$wd" || return
    do_stuff
 }

This function takes an optional single argument, a directory pathname. If given, the function's local wd variable is set to this value. If not given, the local wd variable is set to the static string my_working_dir.

With a small change, you could disallow the function from leaving the user in an unexpected working directory:

do_it () {
    local wd="${1:-my_working_dir}"
    (
        cd "$wd" || return
        do_stuff
    )
 }

The parenthesised subshell's environment inside the function (which includes the current working directory, possibly modified by cd) would not affect the environment of the calling shell.

You would declare this function wherever you usually declare aliases, and you would use it either as

do_it

or with an argument,

do_it some/directory/path

DELETED: I don't understand this question.

Since it appears you want to change the working directory every once in a while, a suggestion would be to replace the alias with a shell function, which could take the directory pathname as a command line argument:

do_it () {
    local wd="${1:-my_working_dir}"
    cd "$wd" || return
    do_stuff
 }

This function takes an optional single argument, a directory pathname. If given, the function's local wd variable is set to this value. If not given, the local wd variable is set to the static string my_working_dir.

With a small change, you could disallow the function from leaving the user in an unexpected working directory:

do_it () {
    local wd="${1:-my_working_dir}"
    (
        cd "$wd" || return
        do_stuff
    )
 }

The parenthesised subshell's environment inside the function (which includes the current working directory, possibly modified by cd) would not affect the environment of the calling shell.

You would declare this function wherever you usually declare aliases, and you would use it either as

do_it

or with an argument,

do_it some/directory/path
Post Deleted by Kusalananda
added 432 characters in body
Source Link
Kusalananda
  • 339.1k
  • 37
  • 684
  • 992

Since it appears you want to change the working directory every once in a while, a suggestion would be to replace the alias with a shell function, which could take the directory pathname as a command line argument:

do_it () {
    local wd="${1:-my_working_dir}"
    cd "$wd" || return
    do_stuff
 }

This function takes an optional single argument, a directory pathname. If given, the function's local wd variable is set to this value. If not given, the local wd variable is set to the static string my_working_dir.

With a small change, you could disallow the function from leaving the user in an unexpected working directory:

do_it () {
    local wd="${1:-my_working_dir}"
    (
        cd "$wd" || return
        do_stuff
    )
 }

The parenthesised subshell's environment inside the function (which includes the current working directory, possibly modified by cd) would not affect the environment of the calling shell.

You would declare this function wherever you usually declare aliases, and you would use it either as

do_it

or with an argument,

do_it some/directory/path

Since it appears you want to change the working directory every once in a while, a suggestion would be to replace the alias with a shell function, which could take the directory pathname as a command line argument:

do_it () {
    local wd="${1:-my_working_dir}"
    cd "$wd" || return
    do_stuff
 }

This function takes an optional single argument, a directory pathname. If given, the function's local wd variable is set to this value. If not given, the local wd variable is set to the static string my_working_dir.

You would declare this function wherever you usually declare aliases, and you would use it either as

do_it

or with an argument,

do_it some/directory/path

Since it appears you want to change the working directory every once in a while, a suggestion would be to replace the alias with a shell function, which could take the directory pathname as a command line argument:

do_it () {
    local wd="${1:-my_working_dir}"
    cd "$wd" || return
    do_stuff
 }

This function takes an optional single argument, a directory pathname. If given, the function's local wd variable is set to this value. If not given, the local wd variable is set to the static string my_working_dir.

With a small change, you could disallow the function from leaving the user in an unexpected working directory:

do_it () {
    local wd="${1:-my_working_dir}"
    (
        cd "$wd" || return
        do_stuff
    )
 }

The parenthesised subshell's environment inside the function (which includes the current working directory, possibly modified by cd) would not affect the environment of the calling shell.

You would declare this function wherever you usually declare aliases, and you would use it either as

do_it

or with an argument,

do_it some/directory/path
added 2 characters in body
Source Link
Kusalananda
  • 339.1k
  • 37
  • 684
  • 992
Loading
Source Link
Kusalananda
  • 339.1k
  • 37
  • 684
  • 992
Loading