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

  • Home
  • SEARCH
  • 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 4613518
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:33:47+00:00 2026-05-22T01:33:47+00:00

I am trying to use script command for logging a bash session. The script

  • 0

I am trying to use script command for logging a bash session.

The script command is executed from withing a bash script but as soon as it is executed, the bash script terminates.

I have tried to invoke the command using various combination always with the same result (termination of the bash script as soon as the command is called). The output that I get is the following:

Script started, file is typescript
root@ubuntu: ...

I have also tried to invoke the command with an & in the end but again with no luck.

Can anyone tell me how should I invoke the command from a bash script?

Thanks

  • 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-22T01:33:48+00:00Added an answer on May 22, 2026 at 1:33 am

    Your shell script did not terminate. It is still running. You are getting a prompt because script is spawning a new shell. the prompt you see is the prompt from the spawned shell.

    The normal use case for script is something like this:

    1. start script. this spawns a new shell.
    2. do commands in the new shell.
    3. exit the shell and drop to previous shell
    4. examine the logfile created by script

    So basically script is working as expected. You will have to find another way to achieve what you want.

    You can log the execution of your script like this:

    #! /bin/bash
    exec > logfile 2>&1
    set -x
    FOO=BAR
    echo $FOO
    

    Explanation:

    • exec > logfile 2>&1 redirects stdout and stderr to logfile
    • set -x makes bash print every command before executing it

    Example:

    $ ./foo.sh
      # (no output here because everything goes to logfile)
    $ cat logfile 
    + FOO=BAR
    + echo BAR
    BAR
    

    Disadvantage of this method is that the script prints no output for humans to see. Everything goes to the logfile.

    Alternatively you can do it like this:

    #! /bin/bash
    # nothing special here
    FOO=BAR
    echo $FOO
    

    Then execute like this:

    $ script -c "bash -x foo.sh"
    Script started, file is typescript
    + FOO=BAR
    + echo BAR
    BAR
    Script done, file is typescript
    

    now output is directly visible and also saved to logfile (default name of logfile is typescript)

    $ cat typescript 
    Script started on Mi 18 Mai 2011 01:05:29 CEST
    + FOO=BAR
    + echo BAR
    BAR
    
    Script done on Mi 18 Mai 2011 01:05:29 CEST
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use mkdir command in a bash script using a * wildcard.
I'm trying to use a shell script to start a command. I don't care
I'm trying to use the foreach loop in an Ant script but I get
I'm trying to use this script (which extracts the domain from a URL): CREATE
I am trying to use optparse but I am having a problem. My script
I have been trying to use the ruby-git gem to make commits etc from
I am trying to use the grep command in a python script using the
I am trying to use Getopt::Long add command line arguments to my script (seen
I'm trying to use CreateProcess to launch a powershell script from within my application.
I am trying to use the following script in asp.net: <script language=javascript type=text/javascript> function

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.