Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 569849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:20:21+00:00 2026-05-13T13:20:21+00:00

I have a customized .profile that I use in ksh and below is a

  • 0

I have a customized .profile that I use in ksh and below is a function that I created to skip back and forth from directories with overly complicated or long names.

As you can see, the pathnames are stored in an array (BOOKMARKS[]) to keep track of them and reference them at a later time. I want to be able to delete certain values from the array, using a case statement (or OPTARG if necessary) so that I can just type bmk -d # to remove the path at the associated index.

I have fiddled around with array +A and -A, but it just wound up screwing up my array (what is left in the commented out code may not be pretty…I didn’t proofread it).

Any suggestions/tips on how to create that functionality? Thanks!

# To bookmark the current directory you are in for easy navigation back and forth from multiple non-aliased directories
# Use like 'bmk' (sets the current directory to a bookmark number) to go back to this directory, i.e. type 'bmk 3' (for the 3rd)
# To find out what directories are linked to which numbers, type 'bmk -l' (lowercase L)
# For every new directory bookmarked, the number will increase so the first time you run 'bmk' it will be 1 then 2,3,4...etc. for every consecutive run therea
fter
# TODO: finish -d (delete bookmark entry) function
make_bookmark()
{
        if [[ $# -eq 0 ]]; then
                BOOKMARKS[${COUNTER}]=${PWD}
                (( COUNTER=COUNTER+1 ))
        else
                case $1 in
                        -l)     NUM_OF_ELEMENTS=${#BOOKMARKS[*]}

                                while [[ ${COUNTER} -lt ${NUM_OF_ELEMENTS} ]]
                                do
                                        (( ACTUAL_NUM=i+1 ))
                                        echo ${ACTUAL_NUM}":"${BOOKMARKS[${i}]}
                                        (( COUNTER=COUNTER+1 ))
                                done
                                break ;;


                       #-d)    ACTUAL_NUM=$2
                                #(( REMOVE=${ACTUAL_NUM}-1 ))
                                #echo "Removing path ${BOOKMARKS[${REMOVE}]} from 'bmk'..."
                                #NUM_OF_ELEMENTS=${#BOOKMARKS[*]}

                                #while [[ ${NUM_OF_ELEMENTS} -gt 0 ]]
                                #do
                                        #if [[ ${NUM_OF_ELEMENTS} -ne ${ACTUAL_NUM} ]]; then
                                        #       TEMP_ARR=$(echo "${BOOKMARKS[*]}")
                                        #       (( NUM_OF_ELEMENTS=${NUM_OF_ELEMENTS}-1 ))
                                        #fi
                                        #echo $TEMP_ARR
                                #done
                                #break
                                #for VALUE in ${TEMP_ARR}
                                #do
                                #       set +A BOOKMARK ${TEMP_ARR}
                                #done
                                #echo ${BOOKMARK[*]}

                                #break ;;

                        *)      (( INDEX=$1-1 ))
                                cd ${BOOKMARKS[${INDEX}]}
                                break ;;
                esac
        fi
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:20:21+00:00Added an answer on May 13, 2026 at 1:20 pm

    Arrays in the Korn shell (and Bash and others) are sparse, so if you use unset to delete members of the array, you won’t be able to use the size of the array as an index to the last member and other limitations.

    Here are some useful snippets (the second for loop is something you might be able to put to use right away):

    array=(1 2 3)
    unset array[2]
    echo ${array[2]}          # null
    indices=(${!array[@]})    # create an array of the indices of "array"
    size=${#indices[@]}       # the size of "array" is the number of indices into it
    size=${#array[@]}         # same
    echo ${array[@]: -1}      # you can use slices to get array elements, -1 is the last one, etc.
    for element in ${array[@]}; do    # iterate over the array without an index
    
    for index in ${indices[@]}        # iterate over the array WITH an index
    do
        echo "Index: ${index}, Element: ${array[index]}"
    done
    
    for index in ${!array[@]}         # iterate over the array WITH an index, directly
    

    That last one can eliminate the need for a counter.

    Here are a couple more handy techniques:

    array+=("new element")    # append a new element without referring to an index
    ((counter++))             # shorter than ((counter=counter+1)) or ((counter+=1))
    if [[ $var == 3 ]]        # you can use the more "natural" comparison operators inside double square brackets
    while [[ $var < 11 ]]     # another example
    echo ${array[${index}-1]  # math inside an array subscript
    

    This all assumes ksh93, some things may not work in earlier versions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made customized user registration page. and i have made that on theme
I have created custom MembershipUser, MembershipProvider and RolePrivoder classes. These all work and I
Dear all, I have a question about Facebook Page: ( NOT user profile page,
I have a 1920x1200 screen an would like to customize VS2008 code windows to
In Eclipse IDE how do you customize the Java code style formatter to have
Ok, so we have clients and those clients get to customize their web facing
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have just started using Visual Studio Professional's built-in unit testing features, which as I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.