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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:35:30+00:00 2026-05-25T01:35:30+00:00

with a basic shell script such as USER=$1 CMD=$2 /usr/bin/sudo -u $USER $CMD I

  • 0

with a basic shell script such as

USER=$1
CMD=$2

/usr/bin/sudo -u $USER $CMD

I can run

# ./script.sh root "/bin/echo 'apple pie'"
'apple pie'

However trying instead:

#/script.sh root "/bin/date -s '2011-08-24 15:24:30'"
date: the argument `15:24:30\'' lacks a leading `+';
when using an option to specify date(s), any non-option
argument must be a format string beginning with `+'
Try `date --help' for more information.

I can replicate the date error by manually typing

/bin/date -s \'2011-08-24 15:24:30\'
date: the argument `15:24:30\'' lacks a leading `+';
when using an option to specify date(s), any non-option
argument must be a format string beginning with `+'
Try `date --help' for more information.

So my problem then with using date in this script is that the single-quotes are getting automatically escaped which date does not like. I can change the script to be based on $1 $2 $3 “$4” but that removes the general purpose nature of this script (which has been simplified for this post).

Any ways to make a script of this nature support the date case without special casing it?

  • 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-25T01:35:30+00:00Added an answer on May 25, 2026 at 1:35 am

    Try this:

    USER=$1
    shift
    
    /usr/bin/sudo -u $USER "$@"
    

    The “$@” preserves the quotes and you should run your script like this instead:

    ./script.sh root /bin/echo 'apple pie'
    

    Note the lack of double quotes.

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

Sidebar

Related Questions

I have a custom shell script that runs each time a user logs in
I have a very basic shell script here: for file in Alt_moabit Book_arrival Door_flowers
I have this Shell script and I've managed to muck it up and I
I have a fish shell script whose default behavior is to send an email
I am attempting to create a php script that can connect thru ssh to
As you know we can change Windows Shell by changing Shell key in HKEY_CURRENT_USER\Software\Microsoft\Windows
I'm an amateur C++ programmer trying to learn about basic shell scripting. I have
I need a very basic, simple and lightweight AJAX script. Does anyone have a
Could you write the easiest possible shell script that will change the desktop wallpaper
I have table ,and i need access them from shell script and do the

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.