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 647961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:46:49+00:00 2026-05-13T21:46:49+00:00

I have a simple function to open an editor: open_an_editor() { nano $1 }

  • 0

I have a simple function to open an editor:

open_an_editor()
{
    nano "$1"
}

If called like open_an_editor file.ext, it works. But if I need to get some output from the function — smth=$(open_an_editor file.ext) — I cannot see the editor, script just stucks. What am I missing here?

Update: I am trying to write a function which would ask the user to write a value in editor, if it wasn’t given in script arguments.

#!/bin/bash
open_an_editor()
{
    if [ "$1" ]
    then
        echo "$1"
        return 0
    fi
    tmpf=$(mktemp -t pref)
    echo "default value, please edit" > "$tmpf"

    # and here the editor should show up,
    # allowing user to edit the value and save it

    # this will stuck without showing the editor:
    #nano "$tmpf"

    # but this, with the help of Kimvais, works perfectly:
    nano "$tmpf" 3>&1 1>&2 2>&3

    cat "$tmpf"
    rm "$tmpf"
}

something=$(open_an_editor "$1")
# and then I can do something useful with that value,
# for example count chars in it
echo -n "$something" | wc -c

So, if the script was called with an argument ./script.sh "A value", the function would just use that and immediately echo 7 bytes. But if called without arguments ./script.sh — nano should pop up.

  • 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-13T21:46:50+00:00Added an answer on May 13, 2026 at 9:46 pm

    If the input you need is the edited file, then you obviously need to cat filename after you do the open_an_editor filename

    If you actually need the output of the editor, then you need to swap stderr and stdin i.e:
    nano "$1" 3>&1 1>&2 2>&3

    If yo need ‘friendly’ user input, see this question on how to use whiptail

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

Sidebar

Ask A Question

Stats

  • Questions 367k
  • Answers 367k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The panel should have a getComponents() method which can use… May 14, 2026 at 4:47 pm
  • Editorial Team
    Editorial Team added an answer What's the view source on your page look like? I… May 14, 2026 at 4:47 pm
  • Editorial Team
    Editorial Team added an answer print(__FUNCTION__) // Swift NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C Swift 3 and… May 14, 2026 at 4:47 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.