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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:56:01+00:00 2026-05-25T20:56:01+00:00

I am trying to run simple shell commands in my script, but am unable

  • 0

I am trying to run simple shell commands in my script, but am unable to get rid of new lines even using chomp or chop.

Is there something I am missing ?

      u=`echo  '#{l}' | cut -d: -f4`.chop()
      p2=`echo '#{l}' | cut -d: -f3`.chop()
      p1=`echo '#{l}' | cut -d: -f2`.chop()
      h=`echo  '#{l}' | cut -d: -f1`.chop()


#     **Cant get newlines to go after p1 and p2 !! ??**
      path="#{p1}/server/#{p2}abc"
      puts path


 Output:
 /usr (p1)
 /server
 /bin (p2) abc 
 Expected Output:
 /usr/server/binabc

Any suggestions ?

As per some suggestions, changed my code to :

h, p1, p2, u = l.split /:/
u.strip 
u.chomp

puts u.inspect

Output: "string\n"

Basically I had tried using chomp before and was hitting the same problem. Do I need to call chomp in a different way or add any gem ?

  • 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-25T20:56:02+00:00Added an answer on May 25, 2026 at 8:56 pm

    Use either String#strip to remove all wrapping whitespace, or String#chomp (note the ‘m’) to remove a single trailing newline only.

    String#chop removes the last character (or \r\n pair) which could be dangerous if the command does not always end with a newline.

    I assume that your code did not work because the results had multiple newlines\whitespace at the end of the output. (And if so, strip will work for you.) You can verify this, however, by removing the call to chop, and then using p u or puts u.inspect to see what characters are actually in the output.

    And for your information, it’s idiomatic in Ruby to omit parentheses when calling methods that take no arguments, e.g. u = foo.chop.

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

Sidebar

Related Questions

I'm trying to run a simple query with $this->db in Kohana, but am running
I am using Python 2.6 and am trying to run a simple random number
I am new to Tomcat, and trying to run a simple HelloWorld servlet. I
I am trying to write a simple shell-script that prints out the first parameter
I am trying to run simple perl dbi example script to connect to mysql
I'm trying to run this simple script in the browser and it keeps erroring
I'm trying to run a simple Watin test through TeamCity but the Internet Explorer
I am trying to run a simple multiple processes application in Python. The main
I am trying to run a simple SQLITE application on Windows Mobile developed with
I am trying to run this dreadfully simple command in Bash java -cp nasa-top-secret.jar

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.