Find the answer to your Linux question:
Results 1 to 6 of 6
This is fairly simple. What I'm trying to achieve is have a folder created with the current unix timestamp. What I'm doing ATM is this: Code: TIME=$(date +%s) mkdir folder-${TIME} ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! Pyrobisqit's Avatar
    Join Date
    May 2011
    Posts
    29

    How to run a command inside a command on a bash script?


    This is fairly simple.

    What I'm trying to achieve is have a folder created with the current unix timestamp.

    What I'm doing ATM is this:

    Code:
    TIME=$(date +%s)
    mkdir folder-${TIME}
    Is there any way to invoke the date +%s command inside the name without having to declare a variable first?

    Thanks!

  2. #2
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    224
    hi,

    of course, if you don't have to re-use the same date (note that uppercase variable names are, by convention, reserved for system environment variables), simply
    Code:
    mkdir directory-$(date +%s)

  3. #3
    Just Joined! Pyrobisqit's Avatar
    Join Date
    May 2011
    Posts
    29
    Quote Originally Posted by watael View Post
    hi,

    of course, if you don't have to re-use the same date (note that uppercase variable names are, by convention, reserved for system environment variables), simply
    Code:
    mkdir directory-$(date +%s)
    What if a malicious user were to declare this:

    Code:
    date=$(malicious_program.bin)

  4. #4
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    224
    no problemo !
    Code:
    $date != date

  5. #5
    Just Joined! Pyrobisqit's Avatar
    Join Date
    May 2011
    Posts
    29
    Quote Originally Posted by watael View Post
    no problemo !
    Code:
    $date != date
    Ok, so parentheses () are for system commands and braces {} are for already declared variables, is that right?

  6. #6
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    224
    $() is command substitution
    ${} is parameter replacement, and is used when you add some string to variable name:
    Code:
    var="blah"
    echo "${var}OtherString"
    otherwise shell would try to expand $varOtherString, which is not assigned

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •